Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console.log no longer EPIPEs in Node@14 (but process.stdout.write does) #10

Open
anko opened this issue May 6, 2020 · 1 comment
Open

Comments

@anko
Copy link

anko commented May 6, 2020

I got here from nodejs/node-v0.x-archive#3211. Thanks for making this.

By default, the following example code from the readme does not throw EPIPE when piped into head, unlike advertised:

;(function log() {
  console.log('tick')
  process.nextTick(log)
})()

Instead, it just loops infinitely writing into an internal buffer until it eats all of your memory. According to nodejs/node#9744 and nodejs/node#11568 this seems to be the intended behaviour.

Anyway, using process.stdout.write instead of console.log does still throw EPIPE:

;(function log() {
  process.stdout.write('tick\n')
  process.nextTick(log)
})()
$ node -v
v14.1.0

This module still fixes both classes of problem:

  • causes the console.log program to exit instead of deathlooping, and
  • causes the process.stdout.write program to exit happy instead of exit sad.

The readme example and prose could use an update to reflect this.

@ignoramous
Copy link

ignoramous commented Feb 9, 2023

We do see EPIPEs on console.log on Node v19, when stdout is redirected to a truncating sink like head / grep when running node with npx clinic flame

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at afterWriteDispatched (node:internal/stream_base_commons:160:15)
    at writeGeneric (node:internal/stream_base_commons:151:3)
    at Socket._writeGeneric (node:net:901:11)
    at Socket._write (node:net:913:8)
    at writeOrBuffer (node:internal/streams/writable:392:12)
    at _write (node:internal/streams/writable:333:10)
    at Writable.write (node:internal/streams/writable:337:10)
    at console.value (node:internal/console/constructor:300:16)
    at console.log (node:internal/console/constructor:377:26)
    at status (/home/murtaza/bravehub/serverless-dns/node_modules/clinic/bin.js:376:15)
Emitted 'error' event on Socket instance at:
    at Socket.onerror (node:internal/streams/readable:785:14)
    at Socket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

Node.js v19.0.1

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

No branches or pull requests

2 participants