Skip to content

fix(worker_threads): gate compiled $MessagePort.Start() Ref by cross-thread status#1256

Merged
nickna merged 1 commit into
mainfrom
worktree-issue-1254
Jul 5, 2026
Merged

fix(worker_threads): gate compiled $MessagePort.Start() Ref by cross-thread status#1256
nickna merged 1 commit into
mainfrom
worktree-issue-1254

Conversation

@nickna

@nickna nickna commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #1254 — the compiled $MessagePort.Start() unconditionally took a keep-alive Ref on the $EventLoop, so a started, unclosed main-thread MessageChannel port kept a compiled program alive forever. The interpreter's SharpTSMessagePort.Start() only Refs the loop for a cross-thread (worker-transferred) port, so this was a compiled-vs-interpreter divergence.

Fix

Mirrors the interpreter's _crossThread / MarkTransferredAcrossThreads split in the emitted $MessagePort (RuntimeEmitter.MessageChannel.cs):

Testing

Test plan

  • dotnet test — 15430/15430 passed
  • dotnet test --filter "FullyQualifiedName~WorkerThreadsTests" — 128/128 passed
  • --compile ... --verify and --compile ... --standalone --verify on the issue's repro — IL verification passed
  • Ran the compiled repro binary directly — prints got:hi and exits with code 0 (previously hung)

…thread status (#1254)

The emitted $MessagePort.Start() unconditionally Ref'd the event loop, so a
started, unclosed in-process MessageChannel port hung a compiled program
forever. SharpTSMessagePort only Refs for a cross-thread (worker-transferred)
port, so this was a compiled-vs-interpreter divergence.

Mirrors the interpreter's _crossThread/MarkTransferredAcrossThreads split:
$MessagePort gains a _crossThread field and a MarkTransferredAcrossThreads()
method (recurses to the partner), and Start() only Refs when set.
CompiledMessagePortBridge.Adopt now calls it when a compiled port is
transferred to a worker, so both ends still Ref while listening (#406).
@nickna nickna merged commit 8b29e48 into main Jul 5, 2026
2 checks passed
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.

Compiled $MessagePort.Start() unconditionally Refs the event loop → started main-thread MessageChannel port hangs the process (dual-mode divergence)

1 participant