Skip to content

Commit

Permalink
Fix ConnectionManager to retry with increment
Browse files Browse the repository at this point in the history
Fails when running master+worker+executor+shell on the same machine.  I think
the issue is that both the shell and the executor attempt to start a
ConnectionManager, which causes port conflicts.  Solution is to attempt and
increment on BindExceptions
  • Loading branch information
ash211 committed Jul 25, 2014
1 parent b80d2fd commit c5a0568
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,24 @@ private[spark] class ConnectionManager(port: Int, conf: SparkConf,
serverChannel.socket.setReuseAddress(true)
serverChannel.socket.setReceiveBufferSize(256 * 1024)

serverChannel.socket.bind(new InetSocketAddress(port))
def bindWithIncrement(port: Int, maxTries: Int = 3) {
for( offset <- 0 until maxTries ) {
try {
serverChannel.socket.bind(new InetSocketAddress(port + offset))
return
} catch {
case e: java.net.BindException => {
if(!e.getMessage.contains("Address already in use") ||
offset == maxTries) {
throw e
}
logInfo("Could not bind on port: " + (port+offset))
}
case e: Exception => throw e
}
}
}
bindWithIncrement(port, 3)
serverChannel.register(selector, SelectionKey.OP_ACCEPT)

val id = new ConnectionManagerId(Utils.localHostName, serverChannel.socket.getLocalPort)
Expand Down

0 comments on commit c5a0568

Please sign in to comment.