[#1183] Fix BlockingOperationException in ChannelGroup.close().awaitUninterruptibly()
This commit is contained in:
parent
f008ac8d47
commit
2b014ce82a
@ -313,7 +313,7 @@ public class DefaultChannelGroup extends AbstractSet<Channel> implements Channel
|
||||
"(name: " + name() + ", size: " + size() + ')';
|
||||
}
|
||||
|
||||
private static final class ImmediateEventExecutor extends AbstractEventExecutorWithoutScheduler {
|
||||
static final class ImmediateEventExecutor extends AbstractEventExecutorWithoutScheduler {
|
||||
|
||||
@Override
|
||||
public EventExecutorGroup parent() {
|
||||
|
@ -18,6 +18,7 @@ package io.netty.channel.group;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.util.concurrent.BlockingOperationException;
|
||||
import io.netty.util.concurrent.DefaultPromise;
|
||||
import io.netty.util.concurrent.EventExecutor;
|
||||
import io.netty.util.concurrent.Future;
|
||||
@ -231,6 +232,14 @@ final class DefaultChannelGroupFuture extends DefaultPromise<Void> implements Ch
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkDeadLock() {
|
||||
EventExecutor e = executor();
|
||||
if (e != null && !(e instanceof DefaultChannelGroup.ImmediateEventExecutor) && e.inEventLoop()) {
|
||||
throw new BlockingOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class DefaultEntry<K, V> implements Map.Entry<K, V> {
|
||||
private final K key;
|
||||
private final V value;
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2013 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.channel.group;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelStateHandlerAdapter;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DefaultChannnelGroupTest {
|
||||
|
||||
|
||||
// Test for #1183
|
||||
@Test
|
||||
public void testNotThrowBlockingOperationException() {
|
||||
final ChannelGroup allChannels = new DefaultChannelGroup();
|
||||
ServerBootstrap b = new ServerBootstrap();
|
||||
|
||||
b.group(new NioEventLoopGroup(), new NioEventLoopGroup());
|
||||
b.childHandler(new ChannelStateHandlerAdapter() {
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) {
|
||||
allChannels.add(ctx.channel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inboundBufferUpdated(ChannelHandlerContext ctx) {
|
||||
}
|
||||
});
|
||||
b.channel(NioServerSocketChannel.class);
|
||||
|
||||
ChannelFuture f = b.bind(0).syncUninterruptibly();
|
||||
|
||||
if (f.isSuccess()) {
|
||||
allChannels.add(f.channel());
|
||||
allChannels.close().awaitUninterruptibly();
|
||||
}
|
||||
b.shutdown();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user