Repository navigation
gh-159418: Fix TypeError in forkserver children when SIGINT has a handler set outside Python - #159484
Open
Om-singhaI wants to merge 1 commit into
Open
Om-singhaI wants to merge 1 commit into
Om-singhaI wants to merge 1 commit into
Conversation
… a handler set outside Python signal.signal() returns None when the handler was already installed outside Python before the interpreter started, for example by a library loaded with LD_PRELOAD. The forkserver stored that None and later passed it back to signal.signal() in every child, which raised TypeError before the target ran. Store SIG_DFL instead so children start normally.
|
The following commit authors need to sign the Contributor License Agreement: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a native library installs a SIGINT handler before Python starts (AMD's
rocprofv3does this),signal.signal()in the forkserver returnsNonefor SIGINT, because Python reports handlers it did not install asNone.forkserver.main()saved thatNoneinold_handlers, and_serve_one()passed it back tosignal.signal()in every child. That raisesTypeError, so each worker exits with code 1 before its target runs. Since forkserver is the default start method on Linux from 3.14, code that used to work now fails.This change stores
signal.SIG_DFLinstead ofNone, since a handler installed from C cannot be restored from Python. I usedSIG_DFLrather thansignal.default_int_handlerbecause the parent never had the Python handler either, and the same loop also covers SIGCHLD.One alternative: when SIGINT already has a handler from C, the forkserver could leave it in place instead of switching to
SIG_IGN, so children inherit the original handler the way they do with fork and spawn. That keeps the library's handler in workers, but the server would no longer ignore Ctrl+C. I went with the smaller change and can switch if that is preferred.Testing, on macOS with a debug build of main (938144e):
DYLD_INSERT_LIBRARIES: the worker exited with code 1 and theTypeErrorbefore, 0 after.signal.signal()reportNonefor SIGINT. It fails without the fix (exit code 1) and passes with it, and it also checks that the child's SIGINT handler isSIG_DFL.test_multiprocessing_forkserverfiltered to the forkserver and preload tests: 31 run, 4 skipped, 0 failures.-R 3:3on the new test reports no leaks.I put the test in
_test_multiprocessing.pyinstead oftest_preload.pybecause 3.14 has notest_preload.py, so the backport can apply cleanly.