From 08474b8f2cfe2225562888973b9593988fb9d5e3 Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Mon, 8 Jul 2024 14:00:31 +0100 Subject: [PATCH] Check resourceManager state first in getMoreLoop JAVA-5516 --- .../operation/CursorResourceManager.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/driver-core/src/main/com/mongodb/internal/operation/CursorResourceManager.java b/driver-core/src/main/com/mongodb/internal/operation/CursorResourceManager.java index cb2e5c58e84..2029cb65aac 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/CursorResourceManager.java +++ b/driver-core/src/main/com/mongodb/internal/operation/CursorResourceManager.java @@ -27,9 +27,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import static com.mongodb.assertions.Assertions.assertNotNull; import static com.mongodb.assertions.Assertions.assertNull; -import static com.mongodb.assertions.Assertions.assertTrue; import static com.mongodb.assertions.Assertions.fail; import static com.mongodb.internal.Locks.withLock; import static com.mongodb.internal.operation.CommandBatchCursorHelper.MESSAGE_IF_CONCURRENT_OPERATION; @@ -220,15 +218,15 @@ ServerCursor getServerCursor() { return serverCursor; } - void setServerCursor(@Nullable final ServerCursor serverCursor) { - assertTrue(state.inProgress()); - assertNotNull(this.serverCursor); - // without `connectionSource` we will not be able to kill `serverCursor` later - assertNotNull(connectionSource); - this.serverCursor = serverCursor; - if (serverCursor == null) { - releaseClientResources(); - } + void setServerCursor(@Nullable final ServerCursor nextServerCursor) { + withLock(lock, () -> { + if (state.inProgress() && serverCursor != null) { + serverCursor = nextServerCursor; + } + if (serverCursor == null) { + releaseClientResources(); + } + }); } void unsetServerCursor() {