Improve the stability of ServerSocketSuspendTest
This commit is contained in:
parent
256f55b2e9
commit
0b71afb81c
@ -72,15 +72,19 @@ public class ServerSocketSuspendTest extends AbstractServerSocketTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Thread.sleep(TIMEOUT / 1000000);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
long startTime = System.nanoTime();
|
long startTime = System.nanoTime();
|
||||||
for (int i = 0; i < NUM_CHANNELS; i ++) {
|
for (int i = 0; i < NUM_CHANNELS; i ++) {
|
||||||
|
System.err.println(i + ": " + System.currentTimeMillis());
|
||||||
Socket s = new Socket();
|
Socket s = new Socket();
|
||||||
s.connect(addr, 10000);
|
s.connect(addr, 10000);
|
||||||
sockets.add(s);
|
sockets.add(s);
|
||||||
}
|
}
|
||||||
long endTime = System.nanoTime();
|
long endTime = System.nanoTime();
|
||||||
|
|
||||||
|
System.err.println(endTime - startTime);
|
||||||
Assert.assertTrue(endTime - startTime < TIMEOUT);
|
Assert.assertTrue(endTime - startTime < TIMEOUT);
|
||||||
} finally {
|
} finally {
|
||||||
for (Socket s: sockets) {
|
for (Socket s: sockets) {
|
||||||
|
@ -17,17 +17,16 @@ package io.netty.bootstrap;
|
|||||||
|
|
||||||
import io.netty.buffer.MessageBuf;
|
import io.netty.buffer.MessageBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelPipeline;
|
|
||||||
import io.netty.channel.ChannelFutureListener;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
|
||||||
import io.netty.channel.ChannelInboundMessageHandler;
|
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
|
import io.netty.channel.ChannelInboundMessageHandler;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
|
import io.netty.channel.ChannelPipeline;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.ServerChannel;
|
import io.netty.channel.ServerChannel;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
@ -232,6 +231,7 @@ public class ServerBootstrap extends AbstractBootstrap<ServerBootstrap> {
|
|||||||
try {
|
try {
|
||||||
childGroup.register(child);
|
childGroup.register(child);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
|
child.unsafe().closeForcibly();
|
||||||
logger.warn("Failed to register an accepted channel: " + child, t);
|
logger.warn("Failed to register an accepted channel: " + child, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -547,6 +547,15 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void closeForcibly() {
|
||||||
|
try {
|
||||||
|
doClose();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn("Failed to close a channel.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void deregister(final ChannelFuture future) {
|
public final void deregister(final ChannelFuture future) {
|
||||||
if (eventLoop().inEventLoop()) {
|
if (eventLoop().inEventLoop()) {
|
||||||
|
@ -248,6 +248,12 @@ public interface Channel extends AttributeMap, ChannelOutboundInvoker, ChannelFu
|
|||||||
*/
|
*/
|
||||||
void close(ChannelFuture future);
|
void close(ChannelFuture future);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the {@link Channel} immediately without firing any events. Probably only useful
|
||||||
|
* when registration attempt failed.
|
||||||
|
*/
|
||||||
|
void closeForcibly();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deregister the {@link Channel} of the {@link ChannelFuture} from {@link EventLoop} and notify the
|
* Deregister the {@link Channel} of the {@link ChannelFuture} from {@link EventLoop} and notify the
|
||||||
* {@link ChannelFuture} once the operation was complete.
|
* {@link ChannelFuture} once the operation was complete.
|
||||||
|
@ -19,9 +19,9 @@ package io.netty.channel.socket.oio;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelException;
|
import io.netty.channel.ChannelException;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelTaskScheduler;
|
||||||
import io.netty.channel.EventLoop;
|
import io.netty.channel.EventLoop;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.ChannelTaskScheduler;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
Loading…
Reference in New Issue
Block a user