private void checkTimeouts()
 {
     lock (_timeoutLock)
     {
         int  minTimeout = Math.Min(sessionTimeoutMs, connectionTimeoutMs);
         long elapsed    = CurrentMillis - Volatile.Read(ref connectionStartMs);
         if (elapsed >= minTimeout)
         {
             if (zooKeeper.hasNewConnectionString())
             {
                 handleNewConnectionString();
             }
             else
             {
                 int maxTimeout = Math.Max(sessionTimeoutMs, connectionTimeoutMs);
                 if (elapsed > maxTimeout)
                 {
                     log.Warn("Connection attempt unsuccessful after {0} "
                              + "(greater than max timeout of {1}). Resetting "
                              + "connection and trying again with a new connection.",
                              elapsed, maxTimeout);
                     reset();
                 }
                 else
                 {
                     var connectionLossException = new CuratorConnectionLossException();
                     log.Error(String.Format("Connection timed out for connection string "
                                             + "({0}) and timeout ({1}) / elapsed ({2})",
                                             zooKeeper.getConnectionString(),
                                             connectionTimeoutMs,
                                             elapsed),
                               connectionLossException);
                     tracer.Get().addCount("connections-timed-out", 1);
                     throw connectionLossException;
                 }
             }
         }
     }
 }
 private void checkTimeouts()
 {
     lock (_timeoutLock)
     {
         int minTimeout = Math.Min(sessionTimeoutMs, connectionTimeoutMs);
         long elapsed = CurrentMillis - Volatile.Read(ref connectionStartMs);
         if ( elapsed >= minTimeout )
         {
             if (zooKeeper.hasNewConnectionString())
             {
                 handleNewConnectionString();
             }
             else
             {
                 int maxTimeout = Math.Max(sessionTimeoutMs, connectionTimeoutMs);
                 if (elapsed > maxTimeout)
                 {
                     log.Warn("Connection attempt unsuccessful after {0} "
                                             + "(greater than max timeout of {1}). Resetting "
                                             + "connection and trying again with a new connection.",
                                             elapsed, maxTimeout);
                     reset();
                 }
                 else
                 {
                     var connectionLossException = new CuratorConnectionLossException();
                     log.Error(String.Format("Connection timed out for connection string "
                                             + "({0}) and timeout ({1}) / elapsed ({2})",
                                             zooKeeper.getConnectionString(),
                                             connectionTimeoutMs,
                                             elapsed),
                                             connectionLossException);
                     tracer.Get().addCount("connections-timed-out", 1);
                     throw connectionLossException;
                 }
             }
         }
     }
 }