HDFS-11508. Fix bind failure in SimpleTCPServer & Portmap where bind fails because socket is in TIME_WAIT state. Contributed by Mukul Kumar Singh.

This commit is contained in:
Arpit Agarwal 2017-03-07 11:41:05 -08:00
parent 959940b0ab
commit 1f9848dfe1
2 changed files with 3 additions and 0 deletions

View File

@ -81,6 +81,7 @@ public ChannelPipeline getPipeline() throws Exception {
}); });
server.setOption("child.tcpNoDelay", true); server.setOption("child.tcpNoDelay", true);
server.setOption("child.keepAlive", true); server.setOption("child.keepAlive", true);
server.setOption("reuseAddress", true);
// Listen to TCP port // Listen to TCP port
ch = server.bind(new InetSocketAddress(port)); ch = server.bind(new InetSocketAddress(port));

View File

@ -109,12 +109,14 @@ public ChannelPipeline getPipeline() throws Exception {
RpcUtil.STAGE_RPC_TCP_RESPONSE); RpcUtil.STAGE_RPC_TCP_RESPONSE);
} }
}); });
tcpServer.setOption("reuseAddress", true);
udpServer = new ConnectionlessBootstrap(new NioDatagramChannelFactory( udpServer = new ConnectionlessBootstrap(new NioDatagramChannelFactory(
Executors.newCachedThreadPool())); Executors.newCachedThreadPool()));
udpServer.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, udpServer.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER,
handler, RpcUtil.STAGE_RPC_UDP_RESPONSE)); handler, RpcUtil.STAGE_RPC_UDP_RESPONSE));
udpServer.setOption("reuseAddress", true);
tcpChannel = tcpServer.bind(tcpAddress); tcpChannel = tcpServer.bind(tcpAddress);
udpChannel = udpServer.bind(udpAddress); udpChannel = udpServer.bind(udpAddress);