Skip to content

fix: retain ending streams until worker exit - #247

Merged
mcollina merged 1 commit into
mainfrom
fix/retain-ending-stream
Sep 2, 2026
Merged

mcollina merged 1 commit into
mainfrom
fix/retain-ending-stream

Conversation

@mcollina

@mcollina mcollina commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Summary

  • retain a strong worker-to-stream reference once end() starts
  • avoid replacing that reference with a WeakRef when READY races with end()
  • run the test suite with --expose-gc and add an inline GC regression test, skipped when GC is unavailable

The worker normally switches to a weak stream reference after startup so abandoned streams can be collected. During end(), however, stream event listeners may be the only remaining references. Because those listeners only form a self-cycle, GC can collect the stream, terminate its worker through the finalization registry, and prevent close from being emitted. This is the timeout seen on Windows/Node 26 in #246 and on main.

Testing

  • npm test
  • regression test repeated 30 times on Windows with Node 26.8.1
  • regression test on Windows with Node 20, 22, and 24

@mcollina
mcollina requested a review from jsumners September 2, 2026 09:59
@mcollina
mcollina force-pushed the fix/retain-ending-stream branch from c91f910 to 48ecd88 Compare September 2, 2026 10:04
@mcollina
mcollina merged commit 7a37b75 into main Sep 2, 2026
59 of 70 checks passed
@mcollina
mcollina deleted the fix/retain-ending-stream branch September 2, 2026 14:22
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