0

I deployed a node app to a free dyno on Heroku. This app functions perfectly locally.

On Heroku, it seems as if the app deploys successfully. Visiting the website, or using heroku open seems to always deliver a working website shortly after deploying using git push heroku master.

Unfortunately, typically a few minutes later, the app crashes. Displaying the following message:

enter image description here

When checking the logs using the command heroku logs --tail, I see the following failure.

enter image description here

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.

I also changed the server launch script to just do node lib/application.js and experienced the same error again.

Any information on where this error may be coming from, a different heroku configuration to use, etc., would be extremely appreciated.

My npm scripts are as follows. 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

Connorelsea
  • 2,308
  • 6
  • 26
  • 47
  • mysql server closing the connection, may this link help http://stackoverflow.com/questions/20210522/nodejs-mysql-error-connection-lost-the-server-closed-the-connection – Jagdish Idhate Aug 01 '16 at 05:19

1 Answers1

1

This isn't a random crash - the application is crashing when its connection to MySQL is closed. Your app needs database reconnection logic.

hunterloftis
  • 13,386
  • 5
  • 48
  • 50