Skip to content

fix(logger): skip pino-pretty transport in tests (closes #2541) - #2543

Merged
bokelley merged 1 commit into
mainfrom
bokelley/vitest-hang-investigation
Apr 20, 2026
Merged

bokelley merged 1 commit into
mainfrom
bokelley/vitest-hang-investigation

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

  • Fix the vitest teardown hang tracked in vitest pre-commit hangs sporadically at teardown (37 zombies across workspaces) #2541.
  • server/src/logger.ts enabled the pino-pretty transport whenever NODE_ENV !== 'production'. Pino's transport spawns a worker thread and registers process.on('exit', ...) (see node_modules/pino/lib/transport.js:149) — the worker thread is a held handle that prevents Node's event loop from draining at test teardown, causing vitest workers to zombie indefinitely.
  • Treat NODE_ENV=test and VITEST=true (auto-set by vitest) as non-dev so tests use the default synchronous stdout destination — no worker thread, no exit listener.

Evidence

Hypothesis test — 4 back-to-back runs of npm run test:unit:

Condition Result
Baseline (NODE_ENV=dev) 1/4 hung at 60s
NODE_ENV=production 0/4 hung
Patch applied (6 runs) 0/6 hung

Zero MaxListenersExceededWarning after the fix (previously consistently emitted: "11 exit listeners added to [process]").

Related

The defensive timeout wrapper and --pool=threads from #2542 stay as belt-and-suspenders against future dependency regressions.

Test plan

  • npm run test:unit — 587 tests pass in ~1.5s
  • npm run typecheck — passes
  • 6 back-to-back runs, all clean exits
  • Build Check CI passes on this PR

🤖 Generated with Claude Code

The pino-pretty transport spawns a worker thread and registers
process.on('exit', ...), which holds the event loop open at vitest
teardown — resulting in zombie workers that could hang pre-commit for
hours. 37 such processes had accumulated across Conductor workspaces,
some running 2 days at 0% CPU.

Treat NODE_ENV=test and VITEST=true (auto-set by vitest) as non-dev so
tests use the default synchronous stdout destination with no worker
thread and no exit listener. Six back-to-back runs confirm the hang is
eliminated.

The defensive timeout wrapper and threads pool from #2542 stay as
belt-and-suspenders against future regressions.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit b7e34dc into main Apr 20, 2026
10 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.

1 participant