[#654] Fix race which could lead to some concurrent side-effects like raise a ConcurrentModificationException when using the nio transport

This commit is contained in:
Norman Maurer 2012-11-07 19:06:20 +01:00
parent 313f777491
commit 1a7e7a1bff

View File

@ -399,7 +399,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
} }
@Override @Override
public final void register(EventLoop eventLoop, ChannelFuture future) { public final void register(EventLoop eventLoop, final ChannelFuture future) {
if (eventLoop == null) { if (eventLoop == null) {
throw new NullPointerException("eventLoop"); throw new NullPointerException("eventLoop");
} }
@ -418,6 +418,25 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
return; return;
} }
// check if the eventLoop which was given is currently in the eventloop.
// if that is the case we are safe to call register, if not we need to
// schedule the execution as otherwise we may say some race-conditions.
//
// See https://github.com/netty/netty/issues/654
if (eventLoop.inEventLoop()) {
register0(future);
} else {
eventLoop.execute(new Runnable() {
@Override
public void run() {
register0(future);
}
});
}
}
private void register0(ChannelFuture future) {
try { try {
Runnable postRegisterTask = doRegister(); Runnable postRegisterTask = doRegister();
registered = true; registered = true;