简体   繁体   English

带有Forever脚本的Node.js有时将无法访问

[英]Nodejs with Forever script will not accessible after sometime

I got a Nodejs project with was hosted in Digital Ocean and I keep it running using Forever script. 我有一个Nodejs项目,该项目托管在Digital Ocean中,并使用Forever脚本保持运行。 But I realized that there will be some error after a period of time which causing the site down. 但是我意识到一段时间后会出现一些错误,导致站点崩溃。 It's not just happened once but few times already, below is the Forever log: 这不仅发生了一次,而且已经发生过几次,下面是永远的日志:

Error: Connection lost: The server closed the connection.
    at Protocol.end (/var/www/menu/node_modules/mysql/lib/protocol/Protocol.js:109:13)
    at Socket.<anonymous> (/var/www/menu/node_modules/mysql/lib/Connection.js:109:28)
    at emitNone (events.js:72:20)
    at Socket.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
    at nextTickCallbackWith2Args (node.js:441:9)
    at process._tickCallback (node.js:355:17)
error: Forever detected script exited with code: 1
error: Script restart attempt #178
Listening on xxx.xxx.xxx.xxx, server_port 80
events.js:141
      throw er; // Unhandled 'error' event

Error: connect ECONNREFUSED 127.0.0.1:3306
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
    --------------------
    at Protocol._enqueue (/var/www/menu/node_modules/mysql/lib/protocol/Protocol.js:141:48)
    at Protocol.handshake (/var/www/menu/node_modules/mysql/lib/protocol/Protocol.js:52:41)
    at Connection.connect (/var/www/menu/node_modules/mysql/lib/Connection.js:130:18)
    at Connection._implyConnect (/var/www/menu/node_modules/mysql/lib/Connection.js:461:10)
    at Connection.query (/var/www/menu/node_modules/mysql/lib/Connection.js:206:8)
    at Object.<anonymous> (/var/www/menu/config/db.js:14:12)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
error: Forever detected script exited with code: 1

I'm not sure why this is happening as the log did not stated which line was causing error, and it seems like Forever had try to restart the script but it failed. 我不确定为什么会这样,因为日志没有说明导致错误的行,而且似乎Forever曾经尝试重新启动脚本,但失败了。 But once I SSH into my server and start it again then it's working fine already. 但是,一旦我SSH进入服务器并再次启动它,它就已经可以正常工作了。 Anyone able to help? 有人能帮忙吗? Thanks. 谢谢。

Error: connect ECONNREFUSED 127.0.0.1:3306

You are getting this error that means that port is in use. 您收到此错误,表示该端口正在使用中。 You can kill the process running over that port by using following command. 您可以使用以下命令杀死在该端口上运行的进程。

sudo kill $(sudo lsof -t -i:3306)

Thereafter, you can re-deploy your server using forever like you do. 之后,您可以像永远一样永久地重新部署服务器。

Happens to me once The problem seems to be related to mysql connection. 发生在我身上问题似乎与mysql连接有关。

Please refer to this stackoverflow question to solve your problem 请参考此stackoverflow问题以解决您的问题

nodejs mysql Error: Connection lost The server closed the connection nodejs mysql错误:连接丢失服务器关闭了连接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM