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

SSL Connection Pool Threading - Stale Connections

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.10.1
    • Component/s: Connection Management
    • Labels:
    • Environment:
      java version "1.7.0_11"
      Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
      Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

      Client is initialized as follows:

      String dbHost = SSL_SERVER_ADDRESS;
      int dbPort = SSL_SERVER_PORT;
      MongoClientOptions o = new MongoClientOptions.Builder()
      .socketFactory(SSLSocketFactory.getDefault())
      .build();
      mongo = new MongoClient(new ServerAddress(dbHost, dbPort), o);

      The mongo object is stored as a singleton and is accessed by other threads.

      Getting a collection, saving and inserting while in the thread that initialized the client is fine. The problem occurs when the client is accessed by other threads. When another thread attempts to get a collection as follows:

      db.getCollection("testCollection");

      I receive the following exception:

      Caused by: com.mongodb.MongoException$Network: can't call something :

      {HOST_NAME}

      /

      {HOST_IP_ADDRESS}

      :

      {PORT}

      /

      {DBNAME}

      at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:295) ~[mongo-java-driver-2.10.1.jar:na]
      at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:257) ~[mongo-java-driver-2.10.1.jar:na]
      at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:310) ~[mongo-java-driver-2.10.1.jar:na]
      at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295) ~[mongo-java-driver-2.10.1.jar:na]
      at com.mongodb.DBCursor._check(DBCursor.java:368) ~[mongo-java-driver-2.10.1.jar:na]
      at com.mongodb.DBCursor._hasNext(DBCursor.java:459) ~[mongo-java-driver-2.10.1.jar:na]
      Caused by: java.io.EOFException: null
      at org.bson.io.Bits.readFully(Bits.java:48) ~[mongo-java-driver-2.10.1.jar:na]
      at org.bson.io.Bits.readFully(Bits.java:33) ~[mongo-java-driver-2.10.1.jar:na]
      at org.bson.io.Bits.readFully(Bits.java:28) ~[mongo-java-driver-2.10.1.jar:na]
      at com.mongodb.Response.<init>(Response.java:40) ~[mongo-java-driver-2.10.1.jar:na]
      at com.mongodb.DBPort.go(DBPort.java:124) ~[mongo-java-driver-2.10.1.jar:na]
      at com.mongodb.DBPort.go(DBPort.java:88) ~[mongo-java-driver-2.10.1.jar:na]

      This exception is generated by any threads that attempt to access a collection in this manner until the number of attempts have exceeded the connection pool size. After this point the exception no longer occur.

      This problem does not occur when a non-SSL connection is made in the following way:

      MongoClientOptions o = new MongoClientOptions.Builder()
      .build();
      mongo = new MongoClient(new ServerAddress(NON_SSL_DB_HOST, DB_PORT), o);

      This leads me to believe that the issue is specific to SSL connections.

      I have also found the following workaround prevents the exceptions from occurring when other threads attempt to access a collection:

      String dbHost = SSL_SERVER_ADDRESS;
      int dbPort = SSL_SERVER_PORT;
      MongoClientOptions o = new MongoClientOptions.Builder()
      .socketFactory(SSLSocketFactory.getDefault())
      .build();
      mongo = new MongoClient(new ServerAddress(dbHost, dbPort), o);
      for(int i = 0 ; i < mongo.getMongoOptions().getConnectionsPerHost(); i++){
      mongo.getDB(dbName).getCollection("testCollection");
      }

      Note the above code is run within the same thread that initializes the client. However, if the collections are cycled through by the initializing thread as in the above code, other threads no longer generate exceptions when accessing a collection.

            Assignee:
            Unassigned Unassigned
            Reporter:
            torbensky Torben Werner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: