Fix race-condition which could lead to a NPE or Exception while register a Channel with a Worker. See #469
This commit is contained in:
parent
36acda0be9
commit
96182f97e8
@ -136,6 +136,8 @@ abstract class AbstractNioWorker implements Worker {
|
||||
void register(AbstractNioChannel<?> channel, ChannelFuture future) {
|
||||
|
||||
Runnable registerTask = createRegisterTask(channel, future);
|
||||
|
||||
synchronized (startStopLock) {
|
||||
Selector selector = start();
|
||||
|
||||
|
||||
@ -143,7 +145,6 @@ abstract class AbstractNioWorker implements Worker {
|
||||
assert offered;
|
||||
|
||||
if (wakenUp.compareAndSet(false, true)) {
|
||||
synchronized (startStopLock) {
|
||||
// wake up the selector to speed things
|
||||
selector = this.selector;
|
||||
|
||||
@ -164,7 +165,6 @@ abstract class AbstractNioWorker implements Worker {
|
||||
* @return selector
|
||||
*/
|
||||
private Selector start() {
|
||||
synchronized (startStopLock) {
|
||||
if (!started) {
|
||||
// Open a selector if this worker didn't start yet.
|
||||
try {
|
||||
@ -195,7 +195,6 @@ abstract class AbstractNioWorker implements Worker {
|
||||
assert selector != null && selector.isOpen();
|
||||
|
||||
started = true;
|
||||
}
|
||||
return selector;
|
||||
}
|
||||
|
||||
@ -322,6 +321,7 @@ abstract class AbstractNioWorker implements Worker {
|
||||
if (!alwaysAsync && Thread.currentThread() == thread) {
|
||||
task.run();
|
||||
} else {
|
||||
synchronized (startStopLock) {
|
||||
start();
|
||||
boolean added = eventQueue.offer(task);
|
||||
|
||||
@ -337,6 +337,8 @@ abstract class AbstractNioWorker implements Worker {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void processRegisterTaskQueue() throws IOException {
|
||||
for (;;) {
|
||||
|
Loading…
Reference in New Issue
Block a user