mirror of
https://github.com/element-hq/synapse.git
synced 2026-08-14 18:01:13 +00:00
swap_current_context already detected being called while a tokio task-local logcontext is in scope, but after logging the error it wrote the thread-local slot anyway. The write is invisible to current_context() (the task-local has read precedence) — and permanent: the paired restore via set_current_context compares against the task-local, sees no change, and skips its swap, so the stray value stays in the slot (and its real occupant is dropped) after the scope ends. Everything the thread does next is misattributed to it, and the stray context is pinned alive on that thread. Bail out after logging instead, leaving the slot untouched, so the damage is confined to the scoped poll. Returns None in that case; the only caller (set_current_context) ignores the return value. Flagged by Copilot review on #19979. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VF56cZ93AqpuGCf8yguCcR