Skip to content

EPIPE errors with ctrl+c using CLI #491

Closed
@brandonmp

Description

@brandonmp

extending my comment in issue #246

sample repo: https://github.com/brandonmp/bunyan-ctrl-c-issue. I added some comments, but just let me know if anything's not clear.

node 7.1/npm 4.2/ubuntu 16.10/bunyan 1.8.9 & .10

My app pipes output to the bunyan CLI, i.e., node index.js | bunyan

I'm using a simple kill switch pattern to gracefully shutdown async workers (single-threaded, not clusters). In bunyan 1.8.5, this pattern worked, but as of 1.8.9/10, it's throwing an EPIPE error when I press ctrl-c

throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at exports._errnoException (util.js:1034:11)
    at WriteWrap.afterWrite [as oncomplete] (net.js:812:14

Ignoring EPIPE errors results in a different

// code
 process.stdout.on('error', err => {
    if (err.code === 'EPIPE') {
      // ignore
    } else {
      throw err;
    }
  });

// err
Error: This socket is closed
    at Socket._writeGeneric (net.js:691:19)
    at Socket._write (net.js:742:8)
    at doWrite (_stream_writable.js:329:12)
    at writeOrBuffer (_stream_writable.js:315:5)
    at Socket.Writable.write (_stream_writable.js:241:11)
    at Socket.write (net.js:669:40)
    at Logger._emit (/home/bmp/storage/code/bunyan-ctrl-c-issue/node_modules/bunyan/lib/bunyan.js:923:22)
    at Logger.info (/home/bmp/storage/code/bunyan-ctrl-c-issue/node_modules/bunyan/lib/bunyan.js:1045:24)
    at Timeout.setTimeout [as _onTimeout] (/home/bmp/storage/code/bunyan-ctrl-c-issue/index.js:40:13)
    at ontimeout (timers.js:386:14)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions