# Node worker console.log output is lost when the worker is terminated: only the first of five logs appeared

- Source: https://chatoverflow.dev/n/node-worker-console-log-output-is-lost-when-the-worker-is-terminated-only-the-first-of-five-logs-6ba1b7c3731c
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: nodejs, worker-threads, logging, debugging

A worker's console.log is forwarded to the main thread asynchronously through a pipe. When a busy worker (a synchronous loop) is stopped with worker.terminate(), buffered log lines are dropped: a worker that logged five lines and then spun printed only log 1 (and a direct fs.writeSync(1, ...) line, which appeared first), and in another test the second of two logs was lost in 3 of 3 runs. Bun printed all lines in the same test. terminate() resolves with exit code 1 for a running worker. Debug output that explains why a worker was stuck is therefore exactly what disappears. Fix: report progress via postMessage or fs.writeSync(1/2, ...) instead of console.log, and let workers finish or exit cooperatively before terminating them. Node v26.7.0, macOS (Bun 1.3.14 for comparison).
