Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2383

Java driver IllegalStateException: state should be: elapsed time is positive

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.4.0
    • Affects Version/s: 3.3.0
    • Component/s: Monitoring
    • None
    • Environment:
      Mongo Java driver 3.3.0, MongoDB 3.2.10 (localhost), Running in WebSphere 8.5.5.10, IBMJAVA7 7.0.9.40, Windows 7 Professional

      I see the following exceptions in my log file.

      [11/14/16 15:55:22:187 CET] 00000b52 cluster       I com.mongodb.diagnostics.logging.SLF4JLogger info Exception in monitor thread while connecting to server localhost:27017
                                       java.lang.IllegalStateException: state should be: elapsed time is positive
      	at com.mongodb.assertions.Assertions.isTrue(Assertions.java:70)
      	at com.mongodb.event.ServerHeartbeatSucceededEvent.<init>(ServerHeartbeatSucceededEvent.java:47)
      	at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:183)
      	at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:123)
      	at java.lang.Thread.run(Thread.java:798)
      

      Code causing the exception:

      class DefaultServerMonitor implements ServerMonitor {
      ...
      private ServerDescription lookupServerDescription(final InternalConnection connection) {
      ...
                  long start = System.nanoTime();
                  try {
                      BsonDocument isMasterResult = executeCommand("admin", new BsonDocument("ismaster", new BsonInt32(1)), connection);
                      long elapsedTimeNanos = System.nanoTime() - start;
                      averageRoundTripTime.addSample(elapsedTimeNanos);
      
                      serverMonitorListener.serverHeartbeatSucceeded(
                              new ServerHeartbeatSucceededEvent(connection.getDescription().getConnectionId(), isMasterResult, elapsedTimeNanos));
      
          public ServerHeartbeatSucceededEvent(final ConnectionId connectionId, final BsonDocument reply, final long elapsedTimeNanos) {
              this.connectionId = notNull("connectionId", connectionId);
              this.reply = notNull("reply", reply);
              isTrue("elapsed time is positive", elapsedTimeNanos > 0);
              this.elapsedTimeNanos = elapsedTimeNanos;
          }
      

      Could the elapsed time be '0' ?
      Maybe the check should be "elapsedTimeNanos >= 0" ?

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            SWitte SWitte [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: