gh-144503: Pass sys.argv to forkserver as real argv elements#148194
gh-144503: Pass sys.argv to forkserver as real argv elements#148194gpshead merged 1 commit intopython:mainfrom
Conversation
Avoid embedding the parent's sys.argv into the forkserver -c command string via repr(). When sys.argv is large (e.g. thousands of file paths from a pre-commit hook), the resulting single argument could exceed the OS per-argument length limit (MAX_ARG_STRLEN on Linux, typically 128 KiB), causing posix_spawn to fail and the parent to observe a BrokenPipeError. Instead, append the argv entries as separate command-line arguments after -c; the forkserver child reads them back as sys.argv[1:]. This cannot exceed any limit the parent itself did not already satisfy. Regression introduced by pythongh-143706 / 298d544.
|
🤖 New build scheduled with the buildbot fleet by @gpshead for commit 77028cd 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F148194%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
|
buildbot result notes (editing as i see things):
|
JelleZijlstra
left a comment
There was a problem hiding this comment.
Yes, this makes sense and feels safer than the alternative.
|
Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
|
Sorry, @gpshead, I could not cleanly backport this to |
|
Sorry, @gpshead, I could not cleanly backport this to |
…ents (pythonGH-148194) Avoid embedding the parent's sys.argv into the forkserver -c command string via repr(). When sys.argv is large (e.g. thousands of file paths from a pre-commit hook), the resulting single argument could exceed the OS per-argument length limit (MAX_ARG_STRLEN on Linux, typically 128 KiB), causing posix_spawn to fail and the parent to observe a BrokenPipeError. Instead, append the argv entries as separate command-line arguments after -c; the forkserver child reads them back as sys.argv[1:]. This cannot exceed any limit the parent itself did not already satisfy. Regression introduced by pythongh-143706 / 298d544. (cherry picked from commit 5e9d90b) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
|
GH-148195 is a backport of this pull request to the 3.14 branch. |
…ents (pythonGH-148194) Avoid embedding the parent's sys.argv into the forkserver -c command string via repr(). When sys.argv is large (e.g. thousands of file paths from a pre-commit hook), the resulting single argument could exceed the OS per-argument length limit (MAX_ARG_STRLEN on Linux, typically 128 KiB), causing posix_spawn to fail and the parent to observe a BrokenPipeError. Instead, append the argv entries as separate command-line arguments after -c; the forkserver child reads them back as sys.argv[1:]. This cannot exceed any limit the parent itself did not already satisfy. Regression introduced by pythongh-143706 / 298d544. (cherry picked from commit 5e9d90b) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
|
GH-148196 is a backport of this pull request to the 3.13 branch. |
|
…H-148194) (#148195) Avoid embedding the parent's sys.argv into the forkserver -c command string via repr(). When sys.argv is large (e.g. thousands of file paths from a pre-commit hook), the resulting single argument could exceed the OS per-argument length limit (MAX_ARG_STRLEN on Linux, typically 128 KiB), causing posix_spawn to fail and the parent to observe a BrokenPipeError. Instead, append the argv entries as separate command-line arguments after -c; the forkserver child reads them back as sys.argv[1:]. This cannot exceed any limit the parent itself did not already satisfy. Regression introduced by gh-143706 / 298d544. (cherry picked from commit 5e9d90b)
…H-148194) (#148196) Avoid embedding the parent's sys.argv into the forkserver -c command string via repr(). When sys.argv is large (e.g. thousands of file paths from a pre-commit hook), the resulting single argument could exceed the OS per-argument length limit (MAX_ARG_STRLEN on Linux, typically 128 KiB), causing posix_spawn to fail and the parent to observe a BrokenPipeError. Instead, append the argv entries as separate command-line arguments after -c; the forkserver child reads them back as sys.argv[1:]. This cannot exceed any limit the parent itself did not already satisfy. Regression introduced by gh-143706 / 298d544. (cherry picked from commit 5e9d90b)
Python 3.15.0a8 introduced a change to `forkserver` spawn mode of `multiprocessing`, and that change was also back-ported to python 3.13.13 and 3.14.4. See: python/cpython#148194 In the modified version, the `sys.argv` elements passed to the `forkserver` process have been moved from the command string (that follows `-c` switch) itself into additional command-line arguments. This breaks our current argument-matching implementation in `multiprocessing` run-time hook, which assumes that the command string is the last passed argument. In addition, the command string itself changed a bit (there is an added `import sys; ` at the beginning). Therefore, revise the argument matching to find the index of `-c` argument, and use the following argument (if available) as the command string to match. Add the pattern for the new forkserver command to ensure match under these new python versions.
Avoid embedding the parent's sys.argv into the forkserver -c command string via repr(). When sys.argv is large (e.g. thousands of file paths from a pre-commit hook), the resulting single argument could exceed the OS per-argument length limit (MAX_ARG_STRLEN on Linux, typically 128 KiB), causing posix_spawn to fail and the parent to observe a BrokenPipeError.
Instead, append the argv entries as separate command-line arguments after -c; the forkserver child reads them back as sys.argv[1:]. This cannot exceed any limit the parent itself did not already satisfy. (well, almost, we consume two more arguments for the
-c blahso the forkserver only works if there are slightly less than the maximum consumption of command line arguments the platform allows, 2MiB total a.k.a. 1/4 stack size for argv+envp space on Linux in most default configs... a far less common scenario than sys.argv repr'ing to >128KiB)Regression introduced by gh-143706 / 298d544 which landed as a bugfix in 3.14.3 and 3.13.12.
This PR is an alternative to #144508, perhaps less risky to backport as a bugfix.
multiprocessing.Poolfails if command has a long list of arguments (regression in 3.14.3, 3.13.12) #144503