Skip to content

Commit c1840a8

Browse files
author
Marcelo Vanzin
committed
[SPARK-7736] [CORE] Fix a race introduced in PythonRunner.
The fix for SPARK-7736 introduced a race where a port value of "-1" could be passed down to the pyspark process, causing it to fail to connect back to the JVM. This change adds code to fix that race. Author: Marcelo Vanzin <[email protected]> Closes apache#8258 from vanzin/SPARK-7736.
1 parent 354f458 commit c1840a8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

core/src/main/scala/org/apache/spark/deploy/PythonRunner.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ object PythonRunner {
5252
gatewayServer.start()
5353
}
5454
})
55-
thread.setName("py4j-gateway")
55+
thread.setName("py4j-gateway-init")
5656
thread.setDaemon(true)
5757
thread.start()
5858

59+
// Wait until the gateway server has started, so that we know which port is it bound to.
60+
// `gatewayServer.start()` will start a new thread and run the server code there, after
61+
// initializing the socket, so the thread started above will end as soon as the server is
62+
// ready to serve connections.
63+
thread.join()
64+
5965
// Build up a PYTHONPATH that includes the Spark assembly JAR (where this class is), the
6066
// python directories in SPARK_HOME (if set), and any files in the pyFiles argument
6167
val pathElements = new ArrayBuffer[String]

0 commit comments

Comments
 (0)