-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 3.3.0
-
Component/s: Query Operations
-
None
If closing a QueryBatchCursor, if the first call throws it counts down a latch but does not set closed to true, meaning all subsequent calls throw an IllegalStateException.
Relevant parts of the stack trace, which occurred after the connected mongod was rolled:
java.lang.IllegalStateException: Attempted to decrement the reference count below 0 at com.mongodb.binding.AbstractReferenceCounted.release(AbstractReferenceCounted.java:39) ~[3rdparty.mongodb-0.jar:na] at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.release(ClusterBinding.java:97) ~[3rdparty.mongodb-0.jar:na] at com.mongodb.operation.QueryBatchCursor.close(QueryBatchCursor.java:151) ~[3rdparty.mongodb-0.jar:na] at com.mongodb.MongoBatchCursorAdapter.close(MongoBatchCursorAdapter.java:41) ~[3rdparty.mongodb-0.jar:na] at com.mongodb.DBCursor.close(DBCursor.java:603) ~[3rdparty.mongodb-0.jar:na] at
I'm not sure whether or not this is expected behavior, but this is a regression from 2.13, where QueryResultIterator set closed=true before calling killCursor: https://github.com/mongodb/mongo-java-driver/blob/2.13.x/src/main/com/mongodb/QueryResultIterator.java#L176 (and we never observed this issue on 2.x)
The obvious fix seems to be moving the closed=true into the finally block or before the try (as per 2.x), but I'm not sure what exactly the expected behavior is when calling close on the same cursor multiple times