Skip to content

Commit 8a73a28

Browse files
authored
Make sure PooledBoltConnection.close is thread-safe (#1576)
1 parent 48becf7 commit 8a73a28

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

driver/src/main/java/org/neo4j/driver/internal/bolt/pooledimpl/PooledBoltConnection.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,17 @@ public CompletionStage<Void> forceClose(String reason) {
269269

270270
@Override
271271
public CompletionStage<Void> close() {
272-
if (closeFuture == null) {
273-
closeFuture = new CompletableFuture<>();
272+
CompletableFuture<Void> closeFuture;
273+
var close = false;
274+
synchronized (this) {
275+
if (this.closeFuture == null) {
276+
this.closeFuture = new CompletableFuture<>();
277+
close = true;
278+
}
279+
closeFuture = this.closeFuture;
280+
}
274281

282+
if (close) {
275283
if (delegate.state() == BoltConnectionState.CLOSED) {
276284
purgeRunnable.run();
277285
closeFuture.complete(null);

0 commit comments

Comments
 (0)