GetMore not closing cursor after exception leading mongos to OOM

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Gone away
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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 Lawley
              Reporter:
              Vinicius Grippa
              None
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: