Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ public void addCloseListener(ActionListener<Void> listener) {
// if the channel is already closed, the listener gets notified immediately, from the same thread.
if (open.get() == false) {
listener.onResponse(null);
// Ensure closeLatch is pulled by completing the closeListener with a noop that is ignored if it is already completed.
// Note that when the channel is closed we may see multiple addCloseListener() calls, so we do not assert on isDone() here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... nor can we rely on the listener with which closeListener is completed itself being completed which is why we pass in a noop() after completing listener directly ourselves. Would you add words to that effect to this comment for the next reader?

This all seems kinda ugly but I don't have a better suggestion.

closeListener.onResponse(ActionListener.assertOnce(ActionListener.noop()));
} else {
assertFalse("close listener already set, only one is allowed!", closeListener.isDone());
closeListener.onResponse(ActionListener.assertOnce(listener));
Expand Down