vert-x3 / vertx-mongo-client

Mongo Client for Eclipse Vert.x
http://vertx.io
Apache License 2.0
58 stars 98 forks source link

OutOfMemoryError when using toReceiveChannel on findBatchWithOptions or aggregate #287

Closed bfreuden closed 2 years ago

bfreuden commented 2 years ago

Motivation:

This is a fix tentative of issue #286 To be honest, it should really be scrutinized by a Vert.x savvy person because those ReadStream, Publisher, InboundBuffer, Channel interactions are definitely beyond my grasp.

Unit tests are still passing, my program no longer fails with OutOfMemoryError, but still... at the end of my program, the capacity of the InboundBuffer (792) is slightly above the specified batchSize (598). It is probably not a good omen.

I also noticed this part of MongoClientImpl:

  @Override
  public ReadStream<JsonObject> findBatchWithOptions(String collection, JsonObject query, FindOptions options) {
    requireNonNull(collection, COLLECTION_CANNOT_BE_NULL);
    requireNonNull(query, QUERY_CANNOT_BE_NULL);
    FindPublisher<JsonObject> view = doFind(collection, query, options);
    return new PublisherAdapter<>(vertx.getOrCreateContext(), view, options.getBatchSize());
  }

Maybe we should call the batchSize(int) method of the FindPublisher between the doFind and before the return new?

bfreuden commented 2 years ago

@tsegismont that's perfect! Thank you :+1: