Skip to content

Commit 32b4bcd

Browse files
Marcelo VanzinHyukjinKwon
authored andcommitted
[SPARK-24029][CORE] Set SO_REUSEADDR on listen sockets.
This allows sockets to be bound even if there are sockets from a previous application that are still pending closure. It avoids bind issues when, for example, re-starting the SHS. Don't enable the option on Windows though. The following page explains some odd behavior that this option can have there: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740621%28v=vs.85%29.aspx I intentionally ignored server sockets that always bind to ephemeral ports, since those don't benefit from this option. Author: Marcelo Vanzin <[email protected]> Closes apache#21110 from vanzin/SPARK-24029.
1 parent 1d758dc commit 32b4bcd

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

common/network-common/src/main/java/org/apache/spark/network/server/TransportServer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.netty.channel.ChannelOption;
3333
import io.netty.channel.EventLoopGroup;
3434
import io.netty.channel.socket.SocketChannel;
35+
import org.apache.commons.lang3.SystemUtils;
3536
import org.slf4j.Logger;
3637
import org.slf4j.LoggerFactory;
3738

@@ -98,7 +99,8 @@ private void init(String hostToBind, int portToBind) {
9899
.group(bossGroup, workerGroup)
99100
.channel(NettyUtils.getServerChannelClass(ioMode))
100101
.option(ChannelOption.ALLOCATOR, allocator)
101-
.childOption(ChannelOption.ALLOCATOR, allocator);
102+
.childOption(ChannelOption.ALLOCATOR, allocator)
103+
.childOption(ChannelOption.SO_REUSEADDR, !SystemUtils.IS_OS_WINDOWS);
102104

103105
this.metrics = new NettyMemoryMetrics(
104106
allocator, conf.getModuleName() + "-server", conf);

core/src/main/scala/org/apache/spark/deploy/rest/RestSubmissionServer.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ private[spark] abstract class RestSubmissionServer(
9494
new HttpConnectionFactory())
9595
connector.setHost(host)
9696
connector.setPort(startPort)
97+
connector.setReuseAddress(!Utils.isWindows)
9798
server.addConnector(connector)
9899

99100
val mainHandler = new ServletContextHandler

core/src/main/scala/org/apache/spark/ui/JettyUtils.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ private[spark] object JettyUtils extends Logging {
344344
connectionFactories: _*)
345345
connector.setPort(port)
346346
connector.setHost(hostName)
347+
connector.setReuseAddress(!Utils.isWindows)
347348

348349
// Currently we only use "SelectChannelConnector"
349350
// Limit the max acceptor number to 8 so that we don't waste a lot of threads

0 commit comments

Comments
 (0)