Skip to content

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

@anko

Description

@anko

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions