Skip to content

Commit 114be1f

Browse files
Remove if check on isDone(), add comment
1 parent 15708f4 commit 114be1f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,9 @@ 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-
}
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+
closeListener.onResponse(ActionListener.assertOnce(ActionListener.noop()));
310309
} else {
311310
assertFalse("close listener already set, only one is allowed!", closeListener.isDone());
312311
closeListener.onResponse(ActionListener.assertOnce(listener));

0 commit comments

Comments
 (0)