Difference in NodeJS termination errors

…衆ロ難τιáo~ 提交于 2021-01-29 09:44:17

问题


I have a NodeJS server running in the background that I start with:

NODE_ENV=production npm start  >> stdout.txt 2>> stderr.txt &

When I restart it with:

kill <node process id>; NODE_ENV=production npm start  >> stdout.txt 2>> stderr.txt &

I sometimes see a long error in the logs:

/opt/bitnami/nodejs/bin/.node.bin[8878]: ../src/node.cc:663:void node::ResetStdio(): Assertion `(0) == (err)' failed.
 1: 0x9ef190 node::Abort() [/opt/bitnami/nodejs/bin/.node.bin]
 2: 0x9ef217  [/opt/bitnami/nodejs/bin/.node.bin]
 3: 0x9bd657 node::ResetStdio() [/opt/bitnami/nodejs/bin/.node.bin]
 4: 0x9bd6c0 node::SignalExit(int) [/opt/bitnami/nodejs/bin/.node.bin]
 5: 0x7fca6718e390  [/lib/x86_64-linux-gnu/libpthread.so.0]
 6: 0x7fca66ebaad3 epoll_wait [/lib/x86_64-linux-gnu/libc.so.6]
 7: 0x13200b0  [/opt/bitnami/nodejs/bin/.node.bin]
 8: 0x130e26b uv_run [/opt/bitnami/nodejs/bin/.node.bin]
 9: 0xa31ec3 node::NodeMainInstance::Run() [/opt/bitnami/nodejs/bin/.node.bin]
10: 0x9c1cc8 node::Start(int, char**) [/opt/bitnami/nodejs/bin/.node.bin]
11: 0x7fca66dd3840 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
12: 0x95c085  [/opt/bitnami/nodejs/bin/.node.bin]
Aborted (core dumped)
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! App@0.0.1 start: `node app.js`
npm ERR! Exit status 134
npm ERR! 
npm ERR! Failed at the App@0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/bitnami/.npm/_logs/2020-12-17T21_05_41_838Z-debug.log
npm[8862]: ../src/node.cc:663:void node::ResetStdio(): Assertion `(0) == (err)' failed.
 1: 0x9ef190 node::Abort() [npm]
 2: 0x9ef217  [npm]
 3: 0x9bd657 node::ResetStdio() [npm]
 4: 0x7fd18c8c7008  [/lib/x86_64-linux-gnu/libc.so.6]
 5: 0x7fd18c8c7055  [/lib/x86_64-linux-gnu/libc.so.6]
 6: 0x994907  [npm]
 7: 0xbc9a29  [npm]
 8: 0xbcb817 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [npm]
 9: 0x13a72b9  [npm]

and sometimes I see a short error:

Terminated
npm ERR! code ELIFECYCLE
npm ERR! errno 143
npm ERR! App@0.0.1 start: `node app.js`
npm ERR! Exit status 143
npm ERR! 
npm ERR! Failed at the App@0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/bitnami/.npm/_logs/2020-12-17T21_06_43_530Z-debug.log

What is the difference between the two, and what is the best way to restart a NodeJS server?


回答1:


don't kill the server (as it might leave bind the best way to shutdown the server, will be to implement a mechanism for gracefully closing the server.

for example, you can do that by catching SIGINT (or any other signal exposed to a process) and handle the server termination.

in nodejs, you can do that by utilizing the process.on()

process.on("SIGINT", () => {
  console.log("SIGINT received");
});

to send a SIGINT to process, do

kill -s SIGINT <node process id>

you might also be interested in this thread



来源:https://stackoverflow.com/questions/65355026/difference-in-nodejs-termination-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!