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.
@@ -334,8 +334,9 @@ class AsyncQueryBatchCursor<T> implements AsyncBatchCursor<T> {
synchronized (lock) {
localCursor = cursor.get();
if (localCursor == null) {
- isClosed.getAndSet(true);
+ if (!isClosed.getAndSet(true)) {
connectionSource.release();
+ }
} else {
connectionSource.retain();
}
