From 004b471e79e2673196da614954241537452de0bd Mon Sep 17 00:00:00 2001 From: YorigamiShion <33752908+YorigamiShion@users.noreply.github.com> Date: Sat, 20 Apr 2024 15:05:13 +0800 Subject: [PATCH] Make connection initialize flag works as expected --- .../core/internal/AsyncConnectionProvider.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/lettuce/core/internal/AsyncConnectionProvider.java b/src/main/java/io/lettuce/core/internal/AsyncConnectionProvider.java index 335450d5eb..ff3019e961 100644 --- a/src/main/java/io/lettuce/core/internal/AsyncConnectionProvider.java +++ b/src/main/java/io/lettuce/core/internal/AsyncConnectionProvider.java @@ -72,17 +72,12 @@ private Sync getSynchronizer(K key) { throw new IllegalStateException("ConnectionProvider is already closed"); } - Sync sync = connections.get(key); - - if (sync != null) { - return sync; - } - AtomicBoolean atomicBoolean = new AtomicBoolean(); - sync = connections.computeIfAbsent(key, connectionKey -> { + Sync sync = connections.computeIfAbsent(key, connectionKey -> { Sync createdSync = new Sync<>(key, connectionFactory.apply(key)); + atomicBoolean.set(true); if (closed) { createdSync.cancel(); @@ -91,7 +86,7 @@ private Sync getSynchronizer(K key) { return createdSync; }); - if (atomicBoolean.compareAndSet(false, true)) { + if (atomicBoolean.get()) { sync.getConnection().whenComplete((c, t) -> {