gh-149816: fix concurrent kwargs growth in _thread.start_new_thread#150168
Open
YvesDup wants to merge 3 commits into
Open
gh-149816: fix concurrent kwargs growth in _thread.start_new_thread#150168YvesDup wants to merge 3 commits into
kwargs growth in _thread.start_new_thread#150168YvesDup wants to merge 3 commits into
Conversation
22 tasks
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.
IMO, to fix this issue, there are 2 options:
in the
PyStack_UnpackDictfunction located in/Objects/call.c, wraps thePyDict_Nextloop in a critical section to prevent concurrent mutations of the same dict.in the
/Modules/_threadmodule.c, duplicate the kwargs dict in thethread_runfunction, before calling the thread's main function. So that the thread will be working with a private copy of the kwargs dict.In the option 1, the
PyStack_UnpackDictfunction is called many times, fromPyObject_VectorcallDictvia_PyObject_VectorcallDictTstate,PyVectorcall_Callvia_PyVectorcall_Callor_PyEvalFramePushAndInit_Ex. This change is not necessary for these functions and, furthermore, would have an impact on their performance.I am in favor of option 2, as it has a more limited scope and shouldn't have a performance impact
on regular builds, while still fixing the issue for FT builds.