NodeJS终止错误的差异 [英] Difference in NodeJS termination errors

查看:61
本文介绍了NodeJS终止错误的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一开始就在后台运行NodeJS服务器:

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

两者之间有什么区别,重启NodeJS服务器的最佳方法是什么?

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

推荐答案

不要杀死服务器(因为它可能会离开绑定关闭服务器的最佳方法是实施一种机制,以正常关闭服务器.

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.

例如,您可以通过捕获 SIGINT(或其他暴露给进程的其他信号)并处理服务器终止.

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

在nodejs中,您可以使用 process.on()

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

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

发送SIGINT进行处理,

to send a SIGINT to process, do

kill -s SIGINT <node process id>

您可能还对此线程

这篇关于NodeJS终止错误的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆