viirya opened a new pull request, #60539:
URL: https://github.com/apache/spark/pull/60539
### What changes were proposed in this pull request?
The pipelined Python UDF path (`BasePythonRunner.createPipelinedDataIn`,
SPARK-56642) sets the socket read timeout that implements the Python worker
idle timeout as
```scala
worker.channel.socket().setSoTimeout(
if (idleTimeoutSeconds > 0) idleTimeoutSeconds.toInt * 1000 else 0)
```
This PR moves the conversion into
`BasePythonRunner.idleTimeoutToSoTimeoutMillis`, which converts with
`TimeUnit.SECONDS.toMillis` on a `Long` and caps the result at `Int.MaxValue`
milliseconds. A timeout of zero (or less) still gives 0, i.e. no timeout.
### Why are the changes needed?
The old expression is `Int` arithmetic, so it overflows when
`spark.python.worker.idleTimeoutSeconds` (or
`spark.sql.execution.pyspark.udf.idleTimeoutSeconds`) is above 2147483 seconds,
about 24.8 days. Both configs accept any non-negative number of seconds. What
happens depends on the value:
| Idle timeout (seconds) | Value passed to `setSoTimeout` | Effect |
|---|---|---|
| 2147484 | -2147483296 | `IllegalArgumentException`, the task fails |
| 4294968 | 704 | the read times out after 0.7 seconds; spurious idle
timeout warnings, and healthy workers are killed if `killOnIdleTimeout` is set |
| 536870912, 4294967296 | 0 | the idle timeout is silently disabled |
| `Long.MaxValue` | -1000 | `IllegalArgumentException`, the task fails |
The synchronous path and `PythonPlannerRunner` wait on the selector with a
`Long` of milliseconds from `TimeUnit.SECONDS.toMillis` and are not affected.
This discrepancy was noted in #60507.
`Socket.setSoTimeout` takes an `Int` of milliseconds, so a read timeout
longer than `Int.MaxValue` milliseconds cannot be expressed. For such an idle
timeout the read now times out after `Int.MaxValue` milliseconds (about 24.8
days), the longest timeout a socket can have, instead of failing, timing out
early or never timing out.
### Does this PR introduce _any_ user-facing change?
Yes. With pipelined mode enabled and a TCP socket to the worker, an idle
timeout above 2147483 seconds no longer fails the task, disables the idle
timeout, or times out after a wrong, shorter period; it is treated as about
24.8 days. Smaller values behave as before.
### How was this patch tested?
Added a unit test in `BasePythonRunnerSuite` for the conversion: zero and
negative values, ordinary values, the largest value that fits, and values that
used to overflow.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Fable 5.2)
This pull request and its description were written by Isaac.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]