Repository navigation
Avoid scheduling duplicate cleanup pending calls while draining (#535) - #538
Open
dianatofficial wants to merge 1 commit into
Open
dianatofficial wants to merge 1 commit into
dianatofficial wants to merge 1 commit into
Conversation
Author
|
CI verification summary for run #46397101637:
|
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.
Fixes #535.
Cause
ThreadState_DestroyNoGIL::AddToCleanupQueuescheduledPendingCallback_DestroyQueuewheneverthread_states_to_destroy.size() == 1. BecausePendingCallback_DestroyQueuepops an entry underthread_states_to_destroy_lockbefore dropping the lock to callDestroyOne(), a second thread exiting duringDestroyOne()makessize() == 1again and schedules a secondPy_AddPendingCallwhilePy_MakePendingCalls()is already running.On CPython 3.11, scheduling a pending call while
make_pending_calls()is executing leaves the eval breaker set and causessys.settrace()to spin indefinitely insideDO_TRACINGifDestroyOne()executes Python code (such asweakrefcallbacks).Fix
cleanup_scheduled(guarded bythread_states_to_destroy_lock) onGreenletGlobals.AddToCleanupQueueschedulesPendingCallback_DestroyQueueonly when!cleanup_scheduledand setscleanup_scheduled = trueifAddPendingCallsucceeds.PendingCallback_DestroyQueueclearscleanup_scheduled = falseinside the same critical section where it observesthread_states_to_destroy.empty().test_cleanup_during_pending_call_with_trace_no_livelockinsrc/greenlet/tests/test_tracing.pyto exercise a second thread queuing cleanup during a main-greenletweakrefcallback undersys.settrace().Verification
Fork CI run (
46395761190):3.10,3.11,3.12,3.13,3.15-dev(Ubuntu & Windows),3.11/3.12(windows-11-arm), and3.14(macos-latest), includingtest_cleanup_during_pending_call_with_trace_no_livelock, as well asCodeQL.pylint-4.1.5rated all modified test files cleanly (the3.14Ubuntu lint job failed only on pre-existingsrc/greenlet/tests/leakcheck.py:300R1716).3.14t,3.15t-dev) hit the pre-existingtest_issue_245_reference_counting_subclass_threadsabort seen onmaster.