title: ClientSession is closed by HornetQ
body: <p>we encountered the following exception in HornetQ (with HornetQ 2.2.5 GA with JBoss 4.3.3, with the InVM connector. both the client and the server are on the same machine):</p>
  
  <p><em>hornetq-failure-check-thread,Connection failure has been detected: Did not receive data from invm:0.</em>
  the error code is 3 (which is HornetQException.CONNECTION_TIMEDOUT).</p>
  
  <p>this causes the RemotingServiceImpl.FailureCheckAndFlushThread to run, which writes the following log multiple times:</p>
  
  <p><em>Client connection failed, clearing up resources for session 95406085-7b3a-11e2-86d3-005056b14e26</em></p>
  
  <p>note that in our application we reuse our ClientSessions. we have one instance of ClientSession per connection (we open multiple connections, one per each client), and the above problem caused one of the sessions to be closed.</p>
  
  <p>after reading this post: <a href="https://community.jboss.org/thread/160367" rel="nofollow">Connection timeout issues - Connection failure has been detected</a></p>
  
  <p>I understood that we need to configure the following on our ServerLocator instance (which is used to create the ClientSessionFactory that creates our ClientSessions):</p>
  
  <pre><code>ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(connectorConfig);
  locator.setClientFailureCheckPeriod(Long.MAX_VALUE);
  locator.setConnectionTTL(-1);
  </code></pre>
  
  <p>this configurtion solved the problem, and the above error was not reproduced.</p>
  
  <p>our problem is the following - in case the sessions will be closed again by HornetQ from some other reason, <strong>how can we create new sessions instead of the closed ones?</strong> </p>
  
  <p>I'm asking this because after we found the session was closed (and before we set the clientFailure and clientTTL values), we tried to create a new session by calling the <em>createSession(false, true, true)</em> method on the <em>ClientSessionFactory</em> instance (we create that instance upon system startup only once and resue it since) and it failed with the following error:</p>
  
  <p><em>HornetQException[errorCode=0 message=Failed to create session]</em></p>
  
  <p>so we didn't succed to create new sessions, and the only solution was restarting the JBoss.</p>
  
  <p>note that we can't restart our application on the client site, so we need to find a way to create new sessions in case the old ones were closed from some reason.</p>