fix(profiler): reset ThreadContinuousScheduler lock after fork - #7275
Open
BetterAndBetterII wants to merge 1 commit into
Open
fix(profiler): reset ThreadContinuousScheduler lock after fork#7275BetterAndBetterII wants to merge 1 commit into
BetterAndBetterII wants to merge 1 commit into
Conversation
If os.fork() runs while ThreadContinuousScheduler.lock is held, the child inherits a locked lock with no owner and ensure_running can deadlock. Mirror the Monitor getsentry#6159 pattern: register_at_fork after_in_child reset. Fixes getsentry#6165
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.
Summary
ThreadContinuousScheduler.lockcan be inherited locked acrossos.fork(). The holding thread does not exist in the child, soensure_runningcan deadlock forever when it tries to acquire the lock.This mirrors the Monitor fix from #6159: register an
os.register_at_fork(after_in_child=...)hook (viaweakref.WeakMethod) that reinitialises the lock and clears the inherited thread / pid /running/ buffer so the child starts clean.Scope is deliberately limited to
ThreadContinuousScheduler(#6165).SessionFlusher/BackgroundWorker(#6164) are left alone.Test plan
python -m pytest tests/profiler/test_continuous_profiler.py::test_thread_continuous_scheduler_lock_reset_in_child_after_fork -vFixes #6165