Skip to content

Commit 8208fcb

Browse files
Fix RestCancellableNodeClientTests.testConcurrentExecuteAndClose() (#129294) (#129425)
Fixes a race condition in testConcurrentExecuteAndClose() where awaitClose() is called before addCloseListener() has been called, resulting in a situation where closeListener is never completed and the closeLatch is never pulled. Closes #129121
1 parent eedb69e commit 8208fcb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

server/src/test/java/org/elasticsearch/rest/action/RestCancellableNodeClientTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ public void addCloseListener(ActionListener<Void> listener) {
303303
// if the channel is already closed, the listener gets notified immediately, from the same thread.
304304
if (open.get() == false) {
305305
listener.onResponse(null);
306+
// Ensure closeLatch is pulled by completing the closeListener with a noop that is ignored if it is already completed.
307+
// Note that when the channel is closed we may see multiple addCloseListener() calls, so we do not assert on isDone() here,
308+
// and since closeListener may already be completed we cannot rely on it to complete the current listener, so we first
309+
// complete it directly and then pass a noop to closeListener.
310+
closeListener.onResponse(ActionListener.assertOnce(ActionListener.noop()));
306311
} else {
307312
assertFalse("close listener already set, only one is allowed!", closeListener.isDone());
308313
closeListener.onResponse(ActionListener.assertOnce(listener));

0 commit comments

Comments
 (0)