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

GetMore not closing cursor after exception leading mongos to OOM

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Gone away
    • None
    • None
    • None
    • None

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              ross@mongodb.com Ross Lawley
              vgrippa@gmail.com VINICIUS GRIPPA
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: