Skip to content

Commit 038a579

Browse files
committed
Trust the server start function to report the port the service started on
1 parent 7c5bdc4 commit 038a579

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

core/src/main/scala/org/apache/spark/HttpServer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private[spark] class HttpServer(resourceBase: File,
4848
private var server: Server = null
4949
private var port: Int = localPort
5050

51-
private def startOnPort(startPort: Int): Server = {
51+
private def startOnPort(startPort: Int): (Server, Int) = {
5252
val server = new Server()
5353
val connector = new SocketConnector
5454
connector.setMaxIdleTime(60*1000)
@@ -79,7 +79,7 @@ private[spark] class HttpServer(resourceBase: File,
7979
server.start()
8080
val actualPort = server.getConnectors()(0).getLocalPort()
8181

82-
server
82+
(server, actualPort)
8383
}
8484

8585
def start() {

core/src/main/scala/org/apache/spark/network/ConnectionManager.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private[spark] class ConnectionManager(port: Int, conf: SparkConf,
104104

105105
private def startService(port: Int) = {
106106
serverChannel.socket.bind(new InetSocketAddress(port))
107-
serverChannel
107+
(serverChannel, port)
108108
}
109109
PortManager.startWithIncrements(port, 3, startService)
110110
serverChannel.register(selector, SelectionKey.OP_ACCEPT)

core/src/main/scala/org/apache/spark/network/PortManager.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ private[spark] object PortManager extends Logging
3838
* @throws SparkException When unable to start service in the given number of attempts
3939
* @return
4040
*/
41-
def startWithIncrements[T](startPort: Int, maxRetries: Int, startService: Int => T):
41+
def startWithIncrements[T](startPort: Int, maxRetries: Int, startService: Int => (T, Int)):
4242
(T, Int) = {
4343
for( offset <- 0 to maxRetries) {
4444
val tryPort = startPort + offset
4545
try {
46-
val service: T = startService(tryPort)
47-
return (service, tryPort)
46+
return startService(tryPort)
4847
} catch {
4948
case e: java.net.BindException => {
5049
if (!e.getMessage.contains("Address already in use") ||

0 commit comments

Comments
 (0)