Files
synapse/rust
Erik JohnstonandClaude Opus 4.8 941c59b8a5 rust logcontext: don't write the thread-local slot from a scoped poll
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
2026-07-21 10:23:42 +00:00
..