[#4241] Ensure NioEventLoopGroup.shutdownGracefully(...) with no quiet period shutdown as fast as expected.

Motivation:

If the user uses 0 as quiet period we should shutdown without any delay if possible.

Modifications:

Ensure we not introduce extra delay when a shutdown quit period of 0 is used.

Result:

EventLoop shutdown as fast as expected.
This commit is contained in:
Norman Maurer 2016-08-02 21:19:30 +02:00
parent 76a3ea699d
commit aa6e6ae307
2 changed files with 27 additions and 1 deletions

View File

@ -696,7 +696,12 @@ public abstract class SingleThreadEventExecutor extends AbstractScheduledEventEx
return true;
}
// There were tasks in the queue. Wait a little bit more until no tasks are queued for the quiet period.
// There were tasks in the queue. Wait a little bit more until no tasks are queued for the quiet period or
// terminate if the quiet period is 0.
// See https://github.com/netty/netty/issues/4241
if (gracefulShutdownQuietPeriod == 0) {
return true;
}
wakeup(true);
return false;
}

View File

@ -21,8 +21,11 @@ import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.EventExecutorGroup;
import io.netty.util.concurrent.Future;
import org.junit.Test;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
public abstract class AbstractEventLoopTest {
@ -60,6 +63,24 @@ public abstract class AbstractEventLoopTest {
assertSame(executor, future.channel().pipeline().context(TestChannelHandler2.class).executor());
}
@Test(timeout = 5000)
public void testShutdownGracefullyNoQuietPeriod() throws Exception {
EventLoopGroup loop = newEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.group(loop)
.channel(newChannel())
.childHandler(new ChannelInboundHandlerAdapter());
// Not close the Channel to ensure the EventLoop is still shutdown in time.
b.bind(0).sync().channel();
Future<?> f = loop.shutdownGracefully(0, 1, TimeUnit.MINUTES);
assertTrue(loop.awaitTermination(2, TimeUnit.SECONDS));
assertTrue(f.syncUninterruptibly().isSuccess());
assertTrue(loop.isShutdown());
assertTrue(loop.isTerminated());
}
private static final class TestChannelHandler extends ChannelDuplexHandler { }
private static final class TestChannelHandler2 extends ChannelDuplexHandler {