igrigorik/agent — Issue #6: Notification channel may block channels indefinitely
Author: nate
Created: 2012-03-02 19:47:14+00:00
State: open

In Selector#select, a Notification channel is created. This channel could be written once per channel given in the select statement. Only the first element in the channel is ever read, and every subsequent attempt to write to it (except the second one, which will succeed since the channel is emptied after the first element is read) will block indefinitely. This is a very real possibility if the Thread switches between the first receive on the Notification channel and when all callbacks are finished being removed from the channels.

I think the solution here is a channel without a max, or a channel which throws away every write but the first one. This wouldn't require any locks at all, keeping things fast.