fix(stream): make native readable refs idempotent

Closed
ST
3d ago
+66-13

What does this PR do?

Make repeated child stdout/stderr ref() calls idempotent. Two calls to ref() followed by one unref() currently leave the parent alive. The native reader already stores a referenced boolean, so remove the competing JavaScript counter and forward the requested state directly.

Both methods return the stream, including after closure. The return-value portion is adapted from @robobun's #36316. That broader Socket proposal retains the counter and does not fix repeated-ref liveness; this change preserves the existing stream classes.

How did you verify your code works?

Built release binaries on macOS arm64 from upstream main 9bd19c98eacc01530a4e7609bc427abffa87d77e and this branch. All three new regressions fail on main: the stdout/stderr cases hit the cleanup watchdog because the parent remains alive, and the chaining case receives undefined. All three pass on the branch, and the complete stdio file passes 12 tests, 0 failures.

bun scripts/build.ts --profile=release --lto=off test --expose-internals test/js/node/child_process/child-process-stdio.test.js

The same subprocess liveness and chaining cases pass on Node 24.21.0. The liveness fixture uses ignored stdin, so it requires no child-pipe handle implementation. Both Bun builds used the same local SDK signpost-warning compatibility patch, excluded from this diff. JS lint, formatting and independent review through P2 pass.