ENOTCONN thrown when calling process.stdin.end() in node 10.1.0

  • Version: 10.1.0, 10.9.0, 10.10.0 (probably every version between 10.1.0 and 10.10.0)
  • Platform: Darwin iMac 17.6.0 Darwin Kernel Version 17.6.0: Tue May 8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64 x86_64

Hi all,

If I run this file:

using node 10.1.0, 10.9.0 or 10.10.0, it throws an ENOTCONN error.

This is the output when using node 10.1.0:

cbm test $ node index.js
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: shutdown ENOTCONN
    at ReadStream.Socket._final (net.js:369:25)
    at callFinal (_stream_writable.js:615:10)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:721:11)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
Emitted 'error' event at:
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    [... lines matching original stack trace ...]
    at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)

But when using node 10.0.0, no error is thrown.

Is that a bug?

It may seem useless, but I'm actually trying to solve this bug for code that looks more like this:

try {
    process.stdin.pipe(process.stdout);
    setTimeout(() => {
        process.stdin.end();
    }, 2000);
} catch (error) {
    console.log('ERROR:');
    console.log(error);
}

So the code I'm working on uses process.stdin.end(); to finish the program. It indeed finishes, but only after throwing the error. By the way (and I don't know if it has something to do with this issue), if I use process.stdin.destroy(); instead of process.stdin.end();, it works as expected.