Skip to content

v3: backport #213 (ignore Node --watch worker messages)#221

Closed
zanlucathiago wants to merge 1 commit into
pinojs:mainfrom
zanlucathiago:v3-backport-watch
Closed

v3: backport #213 (ignore Node --watch worker messages)#221
zanlucathiago wants to merge 1 commit into
pinojs:mainfrom
zanlucathiago:v3-backport-watch

Conversation

@zanlucathiago

Copy link
Copy Markdown

Heads up before reviewing: this PR is built on top of v3.1.0, not on main. GitHub's diff against main will look noisy because the 4.x line moved on. The actual change is the single commit a177143 — feel free to cherry-pick it onto a v3.x maintenance branch and close this PR.

Backports #213 to the 3.x line. Same one-liner in onWorkerMessage plus the regression test, just expressed with tap to match how v3 tests are written.

Why

Node 24.16 shipped on 2026-05-21 with the backport of nodejs/node#62368 (watch: track worker entry files in --watch mode). Once --watch is active, the runtime starts sending tracking messages over parentPort without the protocol code field thread-stream looks for. The default branch in the switch then throws Error: this should not happen: undefined and kills the process on the first tick.

This is the exact case #212 reported on Node 26 and #213 fixed in 4.1.0. The 3.x line never picked the fix — last release on that branch is 3.1.0 from June 2024 — so anyone still on pino@9 (which pins thread-stream: ^3.0.0) breaks on a fresh install the moment they upgrade Node. pino-pretty bumps don't help because the dep flows through pino itself.

Full incident write-up is in #220 with timeline and repro.

What's in the diff

  • index.js: bail out early when the message has no code, before hitting the switch.
  • test/watch-mode.test.js + test/message-without-code.js: the regression test from fix: ignore watch mode worker messages #213, ported to tap (the v3 line still uses tap, not node:test).
  • README.md: short note that messages without a code are ignored, so people writing custom worker events aren't confused.

CI workflow is intentionally untouched — didn't want to widen the scope.

Test

$ ./node_modules/.bin/tap test/watch-mode.test.js
TAP version 13
ok 1 - test/watch-mode.test.js # time=181ms

Full suite was a bit flaky locally on unrelated tests, same as I see on green CI runs for main, so I limited my run to the new test plus base.test.js, both green.

Workaround in the meantime

For anyone landing here from Google: pnpm.overrides (or npm overrides) forcing thread-stream: ^4.0.0 works. But that's not exactly something users would guess from the stack trace alone, which is the motivation for cutting a 3.x patch.

Refs #220.

Node 24.16 (which backports nodejs/node#62368 'watch: track worker
entry files in --watch mode') sends internal tracking messages over
parentPort that don't carry the thread-stream protocol code. The
default branch in onWorkerMessage then throws 'this should not
happen: undefined' and kills the process.

The 4.x line was fixed in pinojs#213 (released as 4.1.0); this is the
same patch applied on top of v3.1.0 so users on pino@9, which
still pins thread-stream ^3.0.0, don't have to ship a package
manager override.

Refs pinojs#220.
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.

1 participant