Skip to content

Commit 90561d0

Browse files
committed
Fix AbstractWriteSearchIndexOperation executeAsync releasing connections (#1812)
Cherry picked from main to 5.5.x Ensure errors thrown outside of the callback also release the resource in AsyncOperationHelper JAVA-5972
1 parent 347a6e6 commit 90561d0

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

driver-core/src/main/com/mongodb/internal/operation/AbstractWriteSearchIndexOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public void executeAsync(final AsyncWriteBinding binding, final SingleResultCall
6666
writeConcernErrorTransformerAsync(binding.getOperationContext().getTimeoutContext()), (result, commandExecutionError) -> {
6767
try {
6868
swallowOrThrow(commandExecutionError);
69-
callback.onResult(result, null);
69+
cb.onResult(result, null);
7070
} catch (Throwable mongoCommandException) {
71-
callback.onResult(null, mongoCommandException);
71+
cb.onResult(null, mongoCommandException);
7272
}
7373
}
7474
)

driver-core/src/main/com/mongodb/internal/operation/AsyncOperationHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ static <R, T extends ReferenceCounted> void withAsyncSuppliedResource(final Asyn
138138
AsyncCallbackSupplier<R> curriedFunction = c -> function.apply(resource, c);
139139
curriedFunction.whenComplete(resource::release).get(errorHandlingCallback);
140140
} catch (Exception e) {
141+
if (resource.getCount() > 0) {
142+
resource.release();
143+
}
141144
errorHandlingCallback.onResult(null, e);
142145
}
143146
}

0 commit comments

Comments
 (0)