Skip to content

Commit b14cf47

Browse files
Fix RestCancellableNodeClientTests.testConcurrentExecuteAndClose()
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 0193dad commit b14cf47

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ 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+
// Handle scenario where awaitClose() was called before any calls to addCloseListener(), this ensures closeLatch is pulled.
307+
if (closeListener.isDone() == false) {
308+
closeListener.onResponse(ActionListener.noop());
309+
}
306310
} else {
307311
assertFalse("close listener already set, only one is allowed!", closeListener.isDone());
308312
closeListener.onResponse(ActionListener.assertOnce(listener));

0 commit comments

Comments
 (0)