java.lang.IllegalStateException: open

JIRA | Dmitry Panov | 1 year ago
  1. 0

    Hello, I've seen a following stack trace: {noformat} java.lang.IllegalStateException: open at org.bson.util.Assertions.isTrue(Assertions.java:36) at com.mongodb.DBPort.runCommand(DBPort.java:219) at com.mongodb.DBPort.ensureOpen(DBPort.java:319) at com.mongodb.DBPort.<init>(DBPort.java:113) at com.mongodb.DBPort.<init>(DBPort.java:95) at com.mongodb.DBPortFactory.create(DBPortFactory.java:28) at com.mongodb.PooledConnectionProvider$ConnectionItemFactory.create(PooledConnectionProvider.java:186) at com.mongodb.PooledConnectionProvider$ConnectionItemFactory.create(PooledConnectionProvider.java:183) at com.mongodb.ConcurrentPool.createNewAndReleasePermitIfFailure(ConcurrentPool.java:150) at com.mongodb.ConcurrentPool.get(ConcurrentPool.java:118) at com.mongodb.PooledConnectionProvider.get(PooledConnectionProvider.java:79) at com.mongodb.DefaultServer.getConnection(DefaultServer.java:61) at com.mongodb.BaseCluster$WrappedServer.getConnection(BaseCluster.java:254) .... {noformat} I could not reproduce it, however I found a potential problem in DBPort.java: {code} do { try { _socket = _options.socketFactory.createSocket(); _socket.connect( _addr.getSocketAddress() , _options.connectTimeout ); _socket.setTcpNoDelay( ! USE_NAGLE ); _socket.setKeepAlive( _options.socketKeepAlive ); _socket.setSoTimeout( _options.socketTimeout ); _in = new BufferedInputStream( _socket.getInputStream() ); _out = _socket.getOutputStream(); successfullyConnected = true; } catch ( IOException e ){ close(); if (!_options.autoConnectRetry || (provider != null && !provider.hasWorked())) throw e; long waitSoFar = System.currentTimeMillis() - start; if (waitSoFar >= maxAutoConnectRetryTime) throw e; if (sleepTime + waitSoFar > maxAutoConnectRetryTime) sleepTime = maxAutoConnectRetryTime - waitSoFar; _logger.log(Level.WARNING, "Exception connecting to " + serverAddress().getHost() + ": " + e + ". Total wait time so far is " + waitSoFar + " ms. Will retry after sleeping for " + sleepTime + " ms."); ThreadUtil.sleep(sleepTime); sleepTime *= 2; } } while (!successfullyConnected); {code} If the first run of the loop results in an IOException, the DBPort is closed which sets the closed flag to true. However, If a subsequent run succeeds the flag is never reset which can cause the above stacktrace. Is it a bug or am I missing something?

    JIRA | 1 year ago | Dmitry Panov
    java.lang.IllegalStateException: open
  2. 0

    Hello, I've seen a following stack trace: {noformat} java.lang.IllegalStateException: open at org.bson.util.Assertions.isTrue(Assertions.java:36) at com.mongodb.DBPort.runCommand(DBPort.java:219) at com.mongodb.DBPort.ensureOpen(DBPort.java:319) at com.mongodb.DBPort.<init>(DBPort.java:113) at com.mongodb.DBPort.<init>(DBPort.java:95) at com.mongodb.DBPortFactory.create(DBPortFactory.java:28) at com.mongodb.PooledConnectionProvider$ConnectionItemFactory.create(PooledConnectionProvider.java:186) at com.mongodb.PooledConnectionProvider$ConnectionItemFactory.create(PooledConnectionProvider.java:183) at com.mongodb.ConcurrentPool.createNewAndReleasePermitIfFailure(ConcurrentPool.java:150) at com.mongodb.ConcurrentPool.get(ConcurrentPool.java:118) at com.mongodb.PooledConnectionProvider.get(PooledConnectionProvider.java:79) at com.mongodb.DefaultServer.getConnection(DefaultServer.java:61) at com.mongodb.BaseCluster$WrappedServer.getConnection(BaseCluster.java:254) .... {noformat} I could not reproduce it, however I found a potential problem in DBPort.java: {code} do { try { _socket = _options.socketFactory.createSocket(); _socket.connect( _addr.getSocketAddress() , _options.connectTimeout ); _socket.setTcpNoDelay( ! USE_NAGLE ); _socket.setKeepAlive( _options.socketKeepAlive ); _socket.setSoTimeout( _options.socketTimeout ); _in = new BufferedInputStream( _socket.getInputStream() ); _out = _socket.getOutputStream(); successfullyConnected = true; } catch ( IOException e ){ close(); if (!_options.autoConnectRetry || (provider != null && !provider.hasWorked())) throw e; long waitSoFar = System.currentTimeMillis() - start; if (waitSoFar >= maxAutoConnectRetryTime) throw e; if (sleepTime + waitSoFar > maxAutoConnectRetryTime) sleepTime = maxAutoConnectRetryTime - waitSoFar; _logger.log(Level.WARNING, "Exception connecting to " + serverAddress().getHost() + ": " + e + ". Total wait time so far is " + waitSoFar + " ms. Will retry after sleeping for " + sleepTime + " ms."); ThreadUtil.sleep(sleepTime); sleepTime *= 2; } } while (!successfullyConnected); {code} If the first run of the loop results in an IOException, the DBPort is closed which sets the closed flag to true. However, If a subsequent run succeeds the flag is never reset which can cause the above stacktrace. Is it a bug or am I missing something?

    JIRA | 1 year ago | Dmitry Panov
    java.lang.IllegalStateException: open
  3. 0

    Mongo org.apache.jackrabbit.oak.plugins.document.DocumentStoreException: Failed to load document with 0:/

    Stack Overflow | 2 years ago | unknown
    org.apache.jackrabbit.oak.plugins.document.DocumentStoreException: Failed to load document with 0:/
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    issue with mongo connection state

    GitHub | 1 year ago | agilliland
    java.lang.IllegalStateException: open

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      open

      at org.bson.util.Assertions.isTrue()
    2. MongoDB Java Driver
      BaseCluster$WrappedServer.getConnection
      1. org.bson.util.Assertions.isTrue(Assertions.java:36)
      2. com.mongodb.DBPort.runCommand(DBPort.java:219)
      3. com.mongodb.DBPort.ensureOpen(DBPort.java:319)
      4. com.mongodb.DBPort.<init>(DBPort.java:113)
      5. com.mongodb.DBPort.<init>(DBPort.java:95)
      6. com.mongodb.DBPortFactory.create(DBPortFactory.java:28)
      7. com.mongodb.PooledConnectionProvider$ConnectionItemFactory.create(PooledConnectionProvider.java:186)
      8. com.mongodb.PooledConnectionProvider$ConnectionItemFactory.create(PooledConnectionProvider.java:183)
      9. com.mongodb.ConcurrentPool.createNewAndReleasePermitIfFailure(ConcurrentPool.java:150)
      10. com.mongodb.ConcurrentPool.get(ConcurrentPool.java:118)
      11. com.mongodb.PooledConnectionProvider.get(PooledConnectionProvider.java:79)
      12. com.mongodb.DefaultServer.getConnection(DefaultServer.java:61)
      13. com.mongodb.BaseCluster$WrappedServer.getConnection(BaseCluster.java:254)
      13 frames