节点ECS任务没有崩溃
我有一个运行Node:Boron(v6.9.0)的ECS工作人员 我时不时地得到一个未被捕获的例外 例如:
{
"date": "Mon Jul 03 2017 09:09:29 GMT+0000 (UTC)",
"process": {
"pid": 28,
"uid": 0,
"gid": 0,
"cwd": "/usr/src/app",
"execPath": "/usr/local/bin/node",
"version": "v6.11.0",
"argv": [
"/usr/local/bin/node",
"/usr/src/app/src/poll.js"
],
"memoryUsage": {
"rss": 67502080,
"heapTotal": 33660928,
"heapUsed": 25145608,
"external": 8981275
}
},
{
"os": {
"loadavg": [
0.65869140625,
0.44921875,
0.4541015625
],
"uptime": 218908
},
"trace": [
{
"column": null,
"file": null,
"function": "Error",
"line": null,
"method": null,
"native": true
}
],
"stack": [
"Error: ENOENT: no such file or directory, open 'FILE.EXE'",
" at Error (native)"
],
"level": "error",
"message": "uncaughtException: ENOENT: no such file or directory, open 'FILE.EXE'",
"message": "uncaughtException: ENOENT: no such file or directory, open 'FILE.EXE'",
"timestamp": "2017-07-03T09:09:29.645Z"
}
我期望发生的事情是应用程序崩溃,重新启动并稍后再试。如果它不能处理x次,它会进入死信队列。
问题是,它只是挂起,当我看到ECS中的任务时,它说" RUNNING"。
因此,它永远不会重启,因为它不会崩溃。
我是否需要做任何配置才能让Node Docker App在未捕获的异常上崩溃?
答案 0 :(得分:1)
将它放在你的脚本中:
process.on('uncaughtException', function (err) {
process.exit(1)
})
答案 1 :(得分:0)
这是失败的代码:
try {
const file = fs.ReadStream(filepath);
file.on('data', (d) => {
task();
}).on('end' () => {
task();
}
} catch (e) {
logger.FATAL(err, {backtrace: err.stack}, () => process.exit(1));
}
感谢@AndyShinn,我为错误事件添加了一个监听器:
.on('error', () => process.exit(1))
现在一切正常。
因此,通过为readable stream添加显式错误侦听器,它已得到修复。