即使在永远使用 JS 之后,Node JS 应用程序也会自行崩溃 [英] Node JS app crashing itself even after using forever JS

查看:20
本文介绍了即使在永远使用 JS 之后,Node JS 应用程序也会自行崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是厌倦了看到我的服务器每次断断续续地停机..每当我醒来时它都停机了.每次我必须去SSH然后运行

I am just tired of seeing my server goes down every time off and on.. Whenever I wake up it is down. Every time I have to go to SSH and then run

forever restartall 

重新启动我的节点应用程序:(

to restart my node app :(

我查看了forever的日志文件,上面写着

I looked into the log file of forever and it says this

error: Forever detected script was killed by signal: SIGKILL
error: Script restart attempt #1

我完全不知道为什么会这样.

I have absolutely no idea why is this happening.

我什至每 50 分钟运行一次 cron 作业以自动重新启动节点 js,以防它自行关闭

I am even running a cron job after every 50 minutes to auto restart node js in case it went down itself

0,50 * * * * * forever restartall

我的应用程序在 Ubuntu EC2 AWS 上运行.我使用以下命令永久启动我的节点应用程序:

My app is running on Ubuntu EC2 AWS. And I use the following command to start my node app using forever:

forever -m5000 -w start index.js

此外,这是最近发生的系统日志的一些最新快照

Also, here are some recent snap of syslog since this happened recently

Jun  1 12:50:01 ip-172-31-28-35 CRON[25924]: (ubuntu) CMD (forever restartall)
Jun  1 12:50:01 ip-172-31-28-35 CRON[25923]: (CRON) info (No MTA installed, discarding output)
Jun  1 13:00:01 ip-172-31-28-35 CRON[25930]: (ubuntu) CMD (forever restartall)
Jun  1 13:00:01 ip-172-31-28-35 CRON[25929]: (CRON) info (No MTA installed, discarding output)
Jun  1 13:05:50 ip-172-31-28-35 dhclient: DHCPREQUEST of 172.31.28.35 on eth0 to 172.31.16.1 port 67 (xid=0x58e67545)
Jun  1 13:05:50 ip-172-31-28-35 dhclient: DHCPACK of 172.31.28.35 from 172.31.16.1
Jun  1 13:05:50 ip-172-31-28-35 dhclient: bound to 172.31.28.35 -- renewal in 1415 seconds.
Jun  1 13:09:01 ip-172-31-28-35 CRON[26000]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -x /usr/lib/php5/sessionclean ] && [ -d /var/lib/php5 ] && /usr/lib/php5/sessionclean /var/lib/php5 $(/usr/lib/php5/maxlifetime))
Jun  1 13:17:01 ip-172-31-28-35 CRON[26016]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jun  1 13:20:01 ip-172-31-28-35 CRON[26023]: (ubuntu) CMD (/home/ubuntu/cron/serv.sh)
Jun  1 13:20:01 ip-172-31-28-35 CRON[26022]: (CRON) info (No MTA installed, discarding output)
Jun  1 13:29:25 ip-172-31-28-35 dhclient: DHCPREQUEST of 172.31.28.35 on eth0 to 172.31.16.1 port 67 (xid=0x58e67545)
Jun  1 13:29:25 ip-172-31-28-35 dhclient: DHCPACK of 172.31.28.35 from 172.31.16.1
Jun  1 13:29:25 ip-172-31-28-35 dhclient: bound to 172.31.28.35 -- renewal in 1560 seconds.
Jun  1 13:34:39 ip-172-31-28-35 crontab[26289]: (ubuntu) LIST (ubuntu)

这是我的 Ubuntu 终端上 free-h 命令的快照:

Here is the snapshot of the free-h command on my terminal of Ubuntu:

这里是 df -h 命令的快照:

and here is snapshot of df -h command:

有什么办法可以解决这个问题并诊断我的应用程序崩溃的原因吗?

Is there any way to fix this and diagnose why my app crashes itself?

遵循建议后的最新编辑和日志:已卸载 MySQL.添加了交换.我添加了未捕获的异常代码现在,当我今天醒来时,服务器再次关闭,这是我的永久日志 http://kl1p.com/AI01 和这些 r 我在崩溃和系统日志截图后的空闲时间 https://snag.gy/WMzqL0..jpghttps://snag.gy/0wG8Dx.jpg

LATEST EDIT AND LOGS AFTER FOLLOWING SUGGESTIONS: Uninstalled MySQL. Added SWAP. I added the uncaught exception code Now when I woke up today the server was again down and this is my forever log http://kl1p.com/AI01 and these r my free-h just after the crash and syslog screenshot https://snag.gy/WMzqL0.jpg https://snag.gy/0wG8Dx.jpg

任何人都可以帮忙看看是什么导致 RAM 被完全使用以及为什么 Node JS 会导致错误,如何修复它们?

Can anyone please help what is causing the RAM to go fully used and why Node JS is causing errors, how to fix them?

推荐答案

我怀疑内存问题.强制永远重启(cron等)只会掩盖真正的问题.

I suspect memory issues. Brute forcing forever restarts (cron's etc) will only mask the real issue.

将此添加到您的代码中:

Add this to your code:

process.on('uncaughtException', function (err) {
  console.log("Uncaught Exception:", err);
  process.exit(1);  // This is VITAL. Don't swallow the err and try to continue.
});

这将允许您开始诊断导致您的节点服务器失败的原因.

This will allow you to begin the process of diagnosing what is causing your node server to fail.

这篇关于即使在永远使用 JS 之后,Node JS 应用程序也会自行崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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