我在Digital Ocean中托管了Nodejs项目,并使用Forever脚本继续运行。但我意识到在一段时间后导致网站崩溃会有一些错误。它不仅发生过一次,而且发生过几次,下面是Forever日志:
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
我不确定为什么会发生这种情况,因为日志没有说明哪一行导致错误,而且看起来Forever尝试重启脚本但是失败了。但是,一旦我SSH到我的服务器并再次启动它,它已经工作正常。有人能帮忙吗?感谢。
答案 0 :(得分:0)
Error: connect ECONNREFUSED 127.0.0.1:3306
您收到此错误表示该端口正在使用中。您可以使用以下命令终止在该端口上运行的进程。
sudo kill $(sudo lsof -t -i:3306)
此后,您可以像以前一样永久地重新部署服务器。
答案 1 :(得分:0)
发生在我身上一次 这个问题似乎与mysql连接有关。
请参阅此stackoverflow问题以解决您的问题
nodejs mysql Error: Connection lost The server closed the connection