1.4 KiB
1.4 KiB
Prompt
User applied the per-key locking patch (f086222d), removed the @pytest.mark.xfail from test_moc_reentry_during_teardown, and found the test STILL fails — now with RuntimeError instead of AssertionError. Asked to diagnose why the fix doesn’t actually resolve this race.
Response summary
Traced the exact scheduling sequence across three concurrent tasks to show that the per-ctx_key locking change doesn’t close the fundamental gap:
maybe_open_context’s finally pops the lock and setsno_more_usersin the exiting caller’s task- But the actual resource cleanup (
values.pop, acm__aexit__,resources.pop) runs in therun_ctxtask insideservice_tn - A re-entering task creates a fresh lock (old one popped), acquires immediately, and hits stale
resources[ctx_key]whilerun_ctxis still in__aexit__
Identified three possible fix strategies: 1. Let run_ctx own lock release/pop after resources.pop() 2. Add a “teardown complete” event that new callers wait on 3. Move resources.pop() into run_ctx’s inner finally (before acm __aexit__)
Files changed
No code changes — analysis only.
Human edits
N/A — diagnostic output, no code generated.