简体   繁体   English

使用nodemon部署到Heroku的Node应用随机崩溃

[英]Node app deployed to Heroku with nodemon randomly crashes

I deployed a node app to a free dyno on Heroku. 我将节点应用程序部署到Heroku上的免费dyno。 This app functions perfectly locally. 这个程序在本地完美运行。

On Heroku, it seems as if the app deploys successfully. 在Heroku上,似乎该应用程序已成功部署。 Visiting the website, or using heroku open seems to always deliver a working website shortly after deploying using git push heroku master . 在使用git push heroku master部署后,访问该网站或使用heroku open似乎总是可以提供一个正常工作的网站。

Unfortunately, typically a few minutes later, the app crashes. 不幸的是,通常在几分钟后,该应用就会崩溃。 Displaying the following message: 显示以下消息:

在此处输入图片说明

When checking the logs using the command heroku logs --tail , I see the following failure. 使用heroku logs --tail命令检查heroku logs --tail ,出现以下故障。

在此处输入图片说明

The redacted information shows the correct server connection information. 编辑的信息显示正确的服务器连接信息。 When the site is working, it shows the correct data from the database. 该站点正常工作时,它将显示数据库中的正确数据。

The problem I am having is that I do not know where this seemingly random error is coming from. 我遇到的问题是,我不知道这个看似随机错误的来源。 I think it has something to do with connecting to MySQL, but I have no clue why the app is restarting or trying to re-connect in the first place. 我认为这与连接MySQL有关,但是我不知道为什么应用程序首先重新启动或尝试重新连接。

I also changed the server launch script to just do node lib/application.js and experienced the same error again. 我还更改了服务器启动脚本,使其仅执行node lib/application.js并再次遇到相同的错误。

Any information on where this error may be coming from, a different heroku configuration to use, etc., would be extremely appreciated. 非常感谢您提供有关此错误可能来自何处,使用不同的heroku配置等的任何信息。

My npm scripts are as follows. 我的npm脚本如下。 None of the build, watch, or clean scripts are being run on the server. 服务器上没有运行任何构建,监视或清除脚本。 For the time being I am building it before deploying. 目前,我正在部署它。

"scripts": {
    "start-local": "nodemon --debug lib/application.js --ignore lib",
    "start": "nodemon --debug lib/application.js --ignore lib",
    "watch": "npm run clean:css && npm run watch:css & npm run watch:js",
    "build:js": "babel src -d lib",
    "watch:js": "nodemon --watch src --exec npm run build:js",
    "build:css": "stylus -u nib res/styles/src/index.styl -o res/styles/lib",
    "watch:css": "stylus -u nib res/styles/src/index.styl -o res/styles/lib -w",
    "clean:css": "rm -rf res/styles/lib && mkdir -p res/styles/lib"
  },

The code that is being run, in application.js, can be found here: http://pastebin.com/4zvBaHK0 可以在以下位置找到正在application.js中运行的代码: http : //pastebin.com/4zvBaHK0

This isn't a random crash - the application is crashing when its connection to MySQL is closed. 这不是随机崩溃-当与MySQL的连接关闭时,应用程序崩溃。 Your app needs database reconnection logic. 您的应用程序需要数据库重新连接逻辑。

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

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