Disconnect and reconnect to a session

It is possible to disconnect from a session and reconnect.

You would want to do this when:

  • You are creating a client that submits workload but does not have to wait for the results. Output can be retrieved anytime by other clients.

  • A client abruptly disconnects from a session but can recover and wants to reconnect later.

Note:
When opening a session, to ensure that the client gets results in the expected manner:
  • If you set the FetchResultsDirectly flag when creating a session, you should also set it when opening the session.

  • If you did not set the FetchResultsDirectly flag when creating the session, you should not set it when opening the session.

About client disconnection

  • There is no limit on the number of times you can connect to or disconnect from a session.

  • Once a session is open on a connection, the connection has exclusive access to the session. Clients cannot simultaneously connect to a session. If a client attempts to connect to an existing session while another client has that session open, the client that was connected loses connection to the session and the new client gains access to the session.

  • Clients which have successfully connected to existing sessions may get output that has already been delivered to a previous client. Client applications must be prepared to handle the same output delivered more than once.

Explicitly disconnect and reconnect to a session

You have a client that submits workload but does not have to wait for the results. Output can be retrieved anytime by other clients.

You can find sample code in the Session Reconnection sample in your Developer Edition installation

  1. Disconnect from a session to be able to reconnect.
    1. Create a connection.
    2. Create a session.
    3. Store the session ID for later retrieval.
    4. Submit tasks.
    5. Close the session with the detach flag.

      This indicates to the session manager that workload should keep running and the session is to remain open.

  2. Reconnect to the session
    1. In the same client or with a different client, create a connection.
    2. Open the session using the original session ID.
    3. Retrieve output and send more tasks as usual.
  3. Allow output to be redistributable to a new client

    Optional.

    In some cases, you may want a new client to retrieve all the output. By default, session manager discards task results once output has been retrieved. You can configure the session type so that session manager will keep the output until the session is closed or aborted.

    1. Open your application profile.
    2. In the SessionType,  add the parameter discardResultsOnDelivery=false.
      <SessionTypes>
              <Type name="DefaultSession" priority="1"recoverable="false" abortSessionIfClientDisconnect="true" sessionRetryLimit="3" taskRetryLimit="3" abortSessionIfTaskFail="false" suspendGracePeriod="100" taskCleanupPeriod="250" persistSessionHistory="all" persistTaskHistory="error" discardResultsOnDelivery="false"/>
      </SessionTypes>
    3. Save your application profile.
    4. Update your application profile with the soamreg command.

Reconnect to a session after client recovery

You have a client that terminated abnormally in the middle of a long-running session. The client may be able to recover and continue working without losing its workload.

  1. Store the session ID.

    When creating a session in your client, store the session ID for later retrieval. This is important. If your client terminates abnormally, you will be able to reconnect to the session.

  2. Configure your session type to not clean up workload when the client disconnects.

    By default, once a client disconnects, workload is cleaned up by the session manager. If your client is recoverable and will attempt to reconnect to sessions, configure workload to not be cleaned up.

    1. Open your application profile.
    2. In the SessionType,  set the parameters abortSessionIfClientDisconnect=false and discardResultsOnDelivery=false.
       <SessionTypes>
              <Type name="DefaultSession" priority="1" recoverable="true"abortSessionIfClientDisconnect="false" sessionRetryLimit="3" taskRetryLimit="3" abortSessionIfTaskFail="false" suspendGracePeriod="100"  taskCleanupPeriod="250" persistSessionHistory="all" persistTaskHistory="error" discardResultsOnDelivery="false"/>
      </SessionTypes>
    3. Save your application profile.
    4. Update your application profile with the soamreg command.
  3. Reconnect when your client recovers.

    When your client terminates abnormally, restart it.

    1. Restart your client when it terminates abnormally.
    2. Create connection.
    3. Open the session using the original session ID.
    4. Continue to operate with the session as usual.

      You can retrieve output or send more tasks as usual.