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

GetMore not closing cursor after exception leading mongos to OOM

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      If we analyze the code:

       

      https://github.com/mongodb/mongo-java-driver/blob/master/driver-core/src/main/com/mongodb/internal/operation/QueryBatchCursor.java#L264

      private void getMore() {
       Connection connection = connectionSource.getConnection();
       try {
       if (serverIsAtLeastVersionThreeDotTwo(connection.getDescription())) {
       try {
       initFromCommandResult(connection.command(namespace.getDatabaseName(),
       asGetMoreCommandDocument(),
       NO_OP_FIELD_NAME_VALIDATOR,
       ReadPreference.primary(),
       CommandResultDocumentCodec.create(decoder, "nextBatch"),
       connectionSource.getSessionContext()));
       } catch (MongoCommandException e) {
       throw translateCommandException(e, serverCursor);
       }
       } else {
       QueryResult<T> getMore = connection.getMore(namespace, serverCursor.getId(),
       getNumberToReturn(limit, batchSize, count), decoder);
       initFromQueryResult(getMore);
       }
       if (limitReached()) {
       killCursor(connection);
       }
       if (serverCursor == null) {
       this.connectionSource.release();
       this.connectionSource = null;
       }
       } finally {
       connection.release();
       }
       }

      The killCursor function is not inside a try..catch/finally so the connection is being closed in case of an exception but the cursor is not.

      In certain situations, the application can start pilling up cursors on mongos leading to OOM.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            vgrippa@gmail.com Vinicius Grippa
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: