title: How to handle Cassandra lost connections?
body: <p>I am fairly new to Cassandra Development using the DataStax C++ driver. I am currently using Cassandra 3.9 and the DataStax C++ driver 2.6. In my C++ application, I am attempting to catch situations where the driver has lost it's connection to Cassandra and then have the application re-attempt to make a connection to Cassandra. I am doing this as follows:</p>
  
  <ol>
  <li>Catch the lost connection before doing a query by checking that cass_future_error_code(connection) != CASS_OK.  If the result is true, then I know that the connection is lost.</li>
  <li>I close the session, free the session, and free the cluster to release resources.</li>
  <li>I recreate the resources and attempt to reconnect to Cassandra.</li>
  </ol>
  
  <p>This approach would be repeated in a separate thread until the connection is re-established.  I have tested this by shutting down the Cassandra Server. I had expected that the application would continue to retry to establish a connection until the Cassandra Server could be restarted and a connection was made.  However, what happened was that the driver threw the following error and my application terminated:</p>
  
  <pre><code>1503345418.300 [WARN] (src/control_connection.cpp:267:virtual void cass::ControlConnection::on_close(cass::Connection*)): Lost control connection to host xx.xx.xx.xx with the following error: Read error 'connection reset by peer'
  1503345418.300 [ERROR] (src/pool.cpp:384:virtual void cass::Pool::on_close(cass::Connection*)): Closing established connection pool to host xx.xx.xx.xx because of the following error: Read error 'connection reset by peer'
  Error: Request timed out
  </code></pre>
  
  <p>Is there a better way to handle lost connections to Cassandra and implement a connection retry?  Any examples or pointers to an example would be greatly appreciated.</p>