1.8 KiB
1.8 KiB
Prompt
User asked to reproduce the exact assert not resources.get(ctx_key) crash originally seen in piker’s brokerd.kraken backend via open_cached_client('kraken'). Key constraints from user:
- In piker, kwargs were the same (empty) so all callers share one
ctx_key = (fid, ()) - The root issue is
_Cache.locksbeing indexed byfidrather thanctx_key, plus the race window betweenvalues.pop()andresources.pop()in_Cache.run_ctx(the acm__aexit__has checkpoints in between) - Mark the test
@pytest.mark.xfailso it can be committed against the unpatched code and later adjusted once the fix from9e49edddis applied
User pointed to piker’s open_cached_client('kraken') usage as the real-world pattern to model.
Response summary
Added test_moc_reentry_during_teardown which deterministically reproduces the teardown race:
- A
cached_client()acm (no params, likekraken.api.get_client()) signals viain_aexitevent when its__aexit__starts, then sleeps to hold the window open use_and_exittask enters+exits the cached resourcereenter_during_teardownwaits onin_aexitthen re-enters — landing exactly in the window wherevaluesis popped butresourcesstill exists- The old
assert not resources.get(ctx_key)fires @pytest.mark.xfail(raises=AssertionError)catches it
Test confirmed: XFAIL with the exact traceback at _mngrs.py:327.
Files changed
tests/test_resource_cache.py— addtest_moc_reentry_during_teardownxfail test fn
Human edits
None — committed as generated (pending user review).