Skip to content

Commit 41a68b2

Browse files
visualagerozza
authored andcommitted
Fix a racing condition during cursor closing.
This can happen if close and next are called on two different threads. It can result in IllegalStateException triggered by decrementing the reference count below 0.
1 parent 9159d33 commit 41a68b2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

driver-core/src/main/com/mongodb/operation/AsyncQueryBatchCursor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,9 @@ private ServerCursor getCursorForNext() {
334334
synchronized (lock) {
335335
localCursor = cursor.get();
336336
if (localCursor == null) {
337-
isClosed.getAndSet(true);
338-
connectionSource.release();
337+
if (!isClosed.getAndSet(true)) {
338+
connectionSource.release();
339+
}
339340
} else {
340341
connectionSource.retain();
341342
}

0 commit comments

Comments
 (0)