[JAVA-2549] AsyncBatchCursor when batchSize is 1 terminates prematurely Created: 10/Jul/17  Updated: 27/Oct/23  Resolved: 10/Jul/17

Status: Closed
Project: Java Driver
Component/s: API, Async
Affects Version/s: 3.4.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Luciano Joublanc [X] Assignee: Ross Lawley
Resolution: Works as Designed Votes: 0
Labels: find
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

It appears that when using the async Java driver, if you create an AsyncBatchCursor via

cursor = collection.find(bson).batchSize(1).batchCursor(callback)

specifically using batchSize = 1, the cursor closes after a single call to next(), even when there are multiple elements to return. i.e. the second call to next() results in null. This behaviour is consistent. Changing the batchSize to > 1 resolves the problem.

I'd be grateful if somebody can confirm they can reproduce this. This looks like something really simple to have been overlooked in testing, so I want to ensure I'm not going nuts!



 Comments   
Comment by Luciano Joublanc [X] [ 10/Jul/17 ]

Hi Ross, thanks for your quick feedback.

Consider updating / adding a hint in the javadoc?

_Returns:
the non-negative batch size. 0 means to use the server default._

Comment by Ross Lawley [ 10/Jul/17 ]

Hi lJoublanc,

Thanks for the ticket, theres no special handling of batchSize in the driver. However, there is in the server:

Specifying 1 or a negative number is analogous to using the limit() method.

The result is the with a batchSize of 1, the cursor is automatically closed by the server. I appreciate that it may be surprising, but it is expected behaviour.

Ross

Generated at Thu Feb 08 08:57:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.