Prevent UberHandler::close from being invoked more than once, Fix
@@ -32,6 +32,8 @@ public final class UberHandler<T extends ClusteredNetworkContext<T>> extends Csp
@NotNull
private final AtomicBoolean isClosing = new AtomicBoolean();
@NotNull
+ private final AtomicBoolean closed = new AtomicBoolean();
+ @NotNull
private final String clusterName;
@Nullable
@@ -184,16 +186,19 @@ public final class UberHandler<T extends ClusteredNetworkContext<T>> extends Csp
* termination event to be sent.
*/
private void closeSoon() {
- isClosing.set(true);
+ if (isClosing.compareAndSet(false, true)) {
@NotNull final ScheduledExecutorService closer = newSingleThreadScheduledExecutor(new NamedThreadFactory("closer", true));
closer.schedule(() -> {
- closer.shutdown();
close();
+ closer.shutdown();
}, 2, SECONDS);
}
+ }
@Override
public void close() {
+ if (closed.compareAndSet(false, true)) {
+
if (!isClosing.getAndSet(true) && connectionChangedNotifier != null)
connectionChangedNotifier.onConnectionChanged(false, nc());
@@ -206,6 +211,7 @@ public final class UberHandler<T extends ClusteredNetworkContext<T>> extends Csp
}
super.close();
}
+ }
@Override
protected void onRead(@NotNull final DocumentContext dc, @NotNull final WireOut outWire) {
@@ -309,4 +315,3 @@ public final class UberHandler<T extends ClusteredNetworkContext<T>> extends Csp
}
}
}
\ No newline at end of file
-
