-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33143][PYTHON] Add configurable timeout to python server and client #30389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
09b1235
17d357b
424be64
d9feed8
6e8e194
f504af3
1595581
a67acd7
0f9e587
cd2d595
d9f0a1b
2913fb1
ef137b6
363f3bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ import scala.concurrent.duration.Duration | |
| import scala.util.Try | ||
|
|
||
| import org.apache.spark.SparkEnv | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.config.Python.PYTHON_AUTH_SOCKET_TIMEOUT | ||
| import org.apache.spark.network.util.JavaUtils | ||
| import org.apache.spark.util.{ThreadUtils, Utils} | ||
|
|
||
|
|
@@ -34,31 +36,38 @@ import org.apache.spark.util.{ThreadUtils, Utils} | |
| * handling one batch of data, with authentication and error handling. | ||
| * | ||
| * The socket server can only accept one connection, or close if no connection | ||
| * in 15 seconds. | ||
| * in configurable amount of seconds (default 15). | ||
| */ | ||
| private[spark] abstract class SocketAuthServer[T]( | ||
| authHelper: SocketAuthHelper, | ||
| threadName: String) { | ||
| threadName: String) extends Logging { | ||
|
|
||
| def this(env: SparkEnv, threadName: String) = this(new SocketAuthHelper(env.conf), threadName) | ||
| def this(threadName: String) = this(SparkEnv.get, threadName) | ||
|
|
||
| private val promise = Promise[T]() | ||
|
|
||
| private def startServer(): (Int, String) = { | ||
| logTrace("Creating listening socket") | ||
| val serverSocket = new ServerSocket(0, 1, InetAddress.getByAddress(Array(127, 0, 0, 1))) | ||
| // Close the socket if no connection in 15 seconds | ||
| serverSocket.setSoTimeout(15000) | ||
| // Close the socket if no connection in the configured seconds | ||
| val timeout = authHelper.conf.get(PYTHON_AUTH_SOCKET_TIMEOUT).toInt | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, actually the test in In Now, I made a change to work around by using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it~ |
||
| logTrace(s"Setting timeout to $timeout sec") | ||
| serverSocket.setSoTimeout(timeout * 1000) | ||
|
|
||
| new Thread(threadName) { | ||
| setDaemon(true) | ||
| override def run(): Unit = { | ||
| var sock: Socket = null | ||
| try { | ||
| logTrace(s"Waiting for connection on port ${serverSocket.getLocalPort}") | ||
| sock = serverSocket.accept() | ||
| logTrace(s"Connection accepted from address ${sock.getRemoteSocketAddress}") | ||
| authHelper.authClient(sock) | ||
| logTrace("Client authenticated") | ||
| promise.complete(Try(handleConnection(sock))) | ||
| } finally { | ||
| logTrace("Closing server") | ||
| JavaUtils.closeQuietly(serverSocket) | ||
| JavaUtils.closeQuietly(sock) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.