We are currently developing an SDK web application that creates a pool of persistent sessions on startup, which are then "handed out" and utilized as requests come into the server. We got the idea for persistent sessions after Empower as several presenters emphasized the overhead associated with the log in process and we have a constant stream of activity that would benefit from simply maintaining a "constant" connection.
So far everything is working as planned, but we wanted to include a step to check that the allocated session is still active, and if not, such as when it has been timed out by the repository, the repository goes down, etc., automatically create a new one to "restock" our session pool.
However, what we have found is that the IsAuthenticated and IsConnected property values do not automatically refresh when sessions are disconnected from outside of the application.
For example, when our application runs and creates the session pool, if I manually terminate them from the Admin console, when our application checks IsAuthenticated or IsConnected, they both still evaluate as True until we actually try to utilize the session and it encounters and exception.
So far, the only way we have found to force a refresh is to try running a process that interacts with the server (currently using Session.GetAllVariables() for testing) within a try-finally to force the properties to refresh before evaluating them; after the exception is handled, the properties reflect that the session is no longer valid and everything works as expected.
Is there a better way to determine whether a session is still active/valid without triggering an exception or iterating through everything using a SessionInfoReader instance?