Skip to content

Suppress ExecutionContext flow in BeginErrorReadLine#1498

Open
ericstj wants to merge 1 commit intomodelcontextprotocol:mainfrom
ericstj:suppress-ec-flow-stderr
Open

Suppress ExecutionContext flow in BeginErrorReadLine#1498
ericstj wants to merge 1 commit intomodelcontextprotocol:mainfrom
ericstj:suppress-ec-flow-stderr

Conversation

@ericstj
Copy link
Copy Markdown
Contributor

@ericstj ericstj commented Apr 3, 2026

Process.BeginErrorReadLine() captures the caller's ExecutionContext, causing AsyncLocal values to leak to the background stderr reader thread. This is undesirable—the stderr handler is a long-lived background I/O callback that shouldn't inherit ambient state from whichever call site happened to create the transport.

Wrap BeginErrorReadLine() in ExecutionContext.SuppressFlow() so the stderr reader gets a clean context.

Add a test that sets an AsyncLocal before creating the transport and verifies the stderr callback does NOT see the value.

Process.BeginErrorReadLine() captures the caller's ExecutionContext,
causing AsyncLocal values to leak to the background stderr reader
thread. This is undesirable—the stderr handler is a long-lived
background I/O callback that shouldn't inherit ambient state from
whichever call site happened to create the transport.

Wrap BeginErrorReadLine() in ExecutionContext.SuppressFlow() so the
stderr reader gets a clean context.

Add a test that sets an AsyncLocal before creating the transport and
verifies the stderr callback does NOT see the value.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub
Copy link
Copy Markdown
Contributor

This is reasonable hygiene, but I'm curious if this is solving some problem you found in the tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants