Require fails when run in a process without stdin
See original GitHub issueOverview
I have a Linux 5.4 server which I am running a NodeJS expressjs app on. This app uses prom-client
.
If I run the app in an interactive terminal everything works fine. However if I run the app in the background it crashes. If I remove require('prom-client')
(and only this) my app works fine in the background.
It looks like prom-client
is trying to read stdin on import, and is failing, thus crashing my process.
Expected Behavior
When I run my NodeJS application without any stdin (in a non-interactive terminal) it should work.
Actual Behavior
When I run my NodeJS application without any stdin it crashes with the error:
+ exec node index.js
hello world
events.js:291
throw er; // Unhandled 'error' event
^
Error: read ENOTCONN
at tryReadStart (net.js:574:20)
at ReadStream.Socket._read (net.js:585:5)
at ReadStream.Readable.read (_stream_readable.js:475:10)
at ReadStream.Socket.read (net.js:625:39)
at ReadStream.Socket (net.js:377:12)
at new ReadStream (tty.js:58:14)
at process.getStdin [as stdin] (internal/bootstrap/switches/is_main_thread.js:151:15)
at get (<anonymous>)
at getOwn (internal/bootstrap/loaders.js:150:5)
at NativeModule.syncExports (internal/bootstrap/loaders.js:258:31)
Emitted 'error' event on ReadStream instance at:
at emitErrorNT (internal/streams/destroy.js:100:8)
at emitErrorCloseNT (internal/streams/destroy.js:68:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: -107,
code: 'ENOTCONN',
syscall: 'read'
}
Details
I have isolated the cause of the crash to require('prom-client')
. If I don’t have this require statement in my app everything works fine.
Here is a 2 line self contained example.
It seems like the program is getting the error ENOTCONN
on a read
system call for the stdin
file descriptor.
The fix to this error is to pipe some sort of stdin to the process in the background:
: | node index.js
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Came across this today and this solved my issue. Thanks for this.
@zbjornson understandable I feel like something downstream from you is causing this issue. Hopefully the workarounds we’ve both posted will help anyone who comes across this from google 😃