diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeysPublic.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeysPublic.java index 3953ea0a7a..0fa78c2f2a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeysPublic.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeysPublic.java @@ -425,6 +425,15 @@ public class CommonConfigurationKeysPublic { "ipc.server.tcpnodelay"; /** Default value for IPC_SERVER_TCPNODELAY_KEY */ public static final boolean IPC_SERVER_TCPNODELAY_DEFAULT = true; + /** + * @see + * + * core-default.xml + */ + public static final String IPC_SERVER_REUSEADDR_KEY = + "ipc.server.reuseaddr"; + /** Default value for IPC_SERVER_REUSEADDR_KEY. */ + public static final boolean IPC_SERVER_REUSEADDR_DEFAULT = true; /** * @see * diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java index 20c0077c4e..94d9bc3313 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java @@ -35,6 +35,7 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.SocketException; +import java.net.StandardSocketOptions; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.channels.CancelledKeyException; @@ -1105,12 +1106,16 @@ private class Listener extends Thread { private int backlogLength = conf.getInt( CommonConfigurationKeysPublic.IPC_SERVER_LISTEN_QUEUE_SIZE_KEY, CommonConfigurationKeysPublic.IPC_SERVER_LISTEN_QUEUE_SIZE_DEFAULT); + private boolean reuseAddr = conf.getBoolean( + CommonConfigurationKeysPublic.IPC_SERVER_REUSEADDR_KEY, + CommonConfigurationKeysPublic.IPC_SERVER_REUSEADDR_DEFAULT); Listener(int port) throws IOException { address = new InetSocketAddress(bindAddress, port); // Create a new server socket and set to non blocking mode acceptChannel = ServerSocketChannel.open(); acceptChannel.configureBlocking(false); + acceptChannel.setOption(StandardSocketOptions.SO_REUSEADDR, reuseAddr); // Bind the server socket to the local host and port bind(acceptChannel.socket(), address, backlogLength, conf, portRangeConfig); diff --git a/hadoop-common-project/hadoop-common/src/main/resources/core-default.xml b/hadoop-common-project/hadoop-common/src/main/resources/core-default.xml index 651ce33b29..933130125f 100644 --- a/hadoop-common-project/hadoop-common/src/main/resources/core-default.xml +++ b/hadoop-common-project/hadoop-common/src/main/resources/core-default.xml @@ -2208,6 +2208,14 @@ + + ipc.server.reuseaddr + true + Enables the SO_REUSEADDR TCP option on the server. + Useful if BindException often prevents a certain service to be restarted + because the server side is stuck in TIME_WAIT state. + +