netty/netty — pull request #2186 by trustin (2014-02-07 00:06:59+00:00)
Title: Fix a race condition in DefaultPromise

.. which occurs when a user adds a listener from different threads after the promise is done and the notifications for the listeners, that were added before the promise is done, is in progress. For instance:

Thread-1: p.addListener(listenerA);
Thread-1: p.setSuccess(null);
Thread-2: p.addListener(listenerB);
Thread-2: p.executor.execute(taskNotifyListenerB);
Thread-1: p.executor.execute(taskNotifyListenerA);

taskNotifyListenerB should not really notify listenerB until taskNotifyListenerA is finished.

To fix this issue, a new volatile flag 'listenersNotified' were added. 'listenersNotified' is set once all listeners added before the promise is done are notified. If 'listenersNotified' is not set, the notifications for the listeners added after the promise is done will be rescheduled for later execution.