javascript - Node 进程结束后Grunt(keep-alive)不退出

标签 javascript node.js gruntjs

Running "express-keepalive" task
[::ffff:xx.xx.xx.xx] CONNECTED
Caught exception: Error: connect ETIMEDOUT
Error: connect ETIMEDOUT
    at exports._errnoException (util.js:746:11)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:983:19)

但即使在此之后,grunt 进程仍继续运行。我已将 gruntserve:dist 设置为作为 Upstart 作业运行,但在 grunt 进程结束之前它不会重生。我正在捕获所有进程错误并确保 Node 进程退出。

process.on('uncaughtException', function(err) {
      console.log('Caught exception: ' + err);
      console.log(err.stack);
      process.exit(1);
});

ps aux 返回没有 Node 进程正在运行。

最佳答案

来自关于 uncaughtException 的 Node 文档:

Note that uncaughtException is a very crude mechanism for exception handling.

Don't use it, use domains instead. If you do use it, restart your application after every unhandled exception!

Do not use it as the node.js equivalent of On Error Resume Next. An unhandled exception means your application - and by extension node.js itself - is in an undefined state. Blindly resuming means anything could happen.

Think of resuming as pulling the power cord when you are upgrading your system. Nine out of ten times nothing happens - but the 10th time, your system is bust.

You have been warned.

关于javascript - Node 进程结束后Grunt(keep-alive)不退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29347077/

相关文章:

javascript - Selenium NodeJS 打印 cookie 到控制台

angularjs - 我如何 "pull-out"只有我实际使用的十几个图标?

javascript - 您可以使用 javascript 来渲染图像流吗?

javascript - 在 typescript 文件中使用 JavaScript 库

javascript - 如何摆脱对象的引用?

javascript - 无法从 Angular 8 服务获取数据

node.js - "Failed to load resource: net::ERR_CONNECTION_REFUSED"用于生产中的 Assets 、css、app.js 和vendor.js(react、babel、webpack)

node.js - nodejs + postgresql 太慢了

javascript - 将谷歌地图 Api 添加到使用 Bower 和 Grunt 构建的项目中

heroku - Grunt Shell + Heroku Push = 无标准输出