Skip to content

Commit

Permalink
Fix RemoteClusterConnection close race (#45898)
Browse files Browse the repository at this point in the history
Closing a `RemoteClusterConnection` concurrently with trying to connect
could result in double invoking the listener.

This fixes
RemoteClusterConnectionTest#testCloseWhileConcurrentlyConnecting

Closes #45845
  • Loading branch information
henningandersen authored Aug 23, 2019
1 parent 6b5e3e9 commit 23673a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,10 @@ void connect(ActionListener<Void> connectListener) {
boolean runConnect = false;
final ActionListener<Void> listener =
ContextPreservingActionListener.wrapPreservingContext(connectListener, threadPool.getThreadContext());
boolean closed;
synchronized (mutex) {
if (closed.get()) {
closed = this.closed.get();
if (closed) {
assert listeners.isEmpty();
} else {
if (listeners.size() >= MAX_LISTENERS) {
Expand All @@ -382,7 +384,7 @@ void connect(ActionListener<Void> connectListener) {
runConnect = listeners.size() == 1;
}
}
if (closed.get()) {
if (closed) {
connectListener.onFailure(new AlreadyClosedException("connect handler is already closed"));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ public void run() {
}
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/45845")
public void testCloseWhileConcurrentlyConnecting() throws IOException, InterruptedException, BrokenBarrierException {
List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
try (MockTransportService seedTransport = startTransport("seed_node", knownNodes, Version.CURRENT);
Expand Down

0 comments on commit 23673a1

Please sign in to comment.