I launched my app on Heroku and added cleardb:ignite as MySQL. The app was running well until it did a MySQL query. The app did receive a successful result from MySQL, but then, in exact 1 minute, the app crashed. The logs is shown as below.
2020-01-20T16:22:50.298705+00:00 heroku[router]: at=info method=GET path="/yas/rest/account" host=kuangs.herokuapp.com request_id=5368da7a-bbfa-4808-b3d8-705c4b908df8 fwd="216.197.177.28" dyno=web.1 connect=0ms service=231ms status=200 bytes=382 protocol=https
2020-01-20T16:23:50.269441+00:00 app[web.1]: events.js:200
2020-01-20T16:23:50.269482+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-01-20T16:23:50.269484+00:00 app[web.1]: ^
2020-01-20T16:23:50.269486+00:00 app[web.1]:
2020-01-20T16:23:50.269489+00:00 app[web.1]: Error: Connection lost: The server closed the connection.
2020-01-20T16:23:50.269491+00:00 app[web.1]: at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:112:13)
2020-01-20T16:23:50.269494+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:97:28)
2020-01-20T16:23:50.269495+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:525:10)
2020-01-20T16:23:50.269497+00:00 app[web.1]: at Socket.emit (events.js:228:7)
2020-01-20T16:23:50.269500+00:00 app[web.1]: at endReadableNT (_stream_readable.js:1185:12)
2020-01-20T16:23:50.269502+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:81:21)
2020-01-20T16:23:50.269504+00:00 app[web.1]: Emitted 'error' event on Connection instance at:
2020-01-20T16:23:50.269507+00:00 app[web.1]: at Connection._handleProtocolError (/app/node_modules/mysql/lib/Connection.js:426:8)
2020-01-20T16:23:50.269509+00:00 app[web.1]: at Protocol.emit (events.js:223:5)
2020-01-20T16:23:50.269511+00:00 app[web.1]: at Protocol._delegateError (/app/node_modules/mysql/lib/protocol/Protocol.js:398:10)
2020-01-20T16:23:50.269513+00:00 app[web.1]: at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:116:8)
2020-01-20T16:23:50.269515+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:97:28)
2020-01-20T16:23:50.269517+00:00 app[web.1]: [... lines matching original stack trace ...]
2020-01-20T16:23:50.269519+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:81:21) {
2020-01-20T16:23:50.269520+00:00 app[web.1]: fatal: true,
2020-01-20T16:23:50.269522+00:00 app[web.1]: code: 'PROTOCOL_CONNECTION_LOST'
2020-01-20T16:23:50.269524+00:00 app[web.1]: }
2020-01-20T16:23:50.292322+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-01-20T16:23:50.292783+00:00 app[web.1]: npm ERR! errno 1
2020-01-20T16:23:50.294244+00:00 app[web.1]: npm ERR! myappnode.github@1.0.0 start: `node server.js`
2020-01-20T16:23:50.294463+00:00 app[web.1]: npm ERR! Exit status 1
2020-01-20T16:23:50.294714+00:00 app[web.1]: npm ERR!
2020-01-20T16:23:50.294917+00:00 app[web.1]: npm ERR! Failed at the myappnode.github@1.0.0 start script.
2020-01-20T16:23:50.295113+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-01-20T16:23:51.112899+00:00 app[web.1]:
2020-01-20T16:23:51.113277+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-01-20T16:23:51.113508+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-01-20T16_23_50_296Z-debug.log
2020-01-20T16:23:51.370082+00:00 heroku[web.1]: State changed from up to crashed
2020-01-20T16:23:51.374569+00:00 heroku[web.1]: State changed from crashed to starting
2020-01-20T16:23:51.359737+00:00 heroku[web.1]: Process exited with status 1
2020-01-20T16:23:53.296185+00:00 heroku[web.1]: Starting process with command `npm start`
2020-01-20T16:23:55.203013+00:00 app[web.1]:
2020-01-20T16:23:55.203038+00:00 app[web.1]: > myappnode.github@1.0.0 start /app
2020-01-20T16:23:55.203041+00:00 app[web.1]: > node server.js
2020-01-20T16:23:55.203043+00:00 app[web.1]:
2020-01-20T16:23:55.355499+00:00 app[web.1]: Server is running on port 21066
2020-01-20T16:23:55.802193+00:00 heroku[web.1]: State changed from starting to up
From the above log we can read that at the time 16:22:50.298705
, I sent a restful request to get the account list. (The app would sent a query to MySQL and the result was successful and correct.) And then exactly in 1 minute, at 16:23:50.269441
, the app crashed.
If I keep doing query before 1 minute expires, the app won't crash and returns the correct query result. But once I stop doing the query, then in 1 minute, the app crashes.
I am suspecting that once a connection is set between the app and the cleardb, a one-minute timer is started. And if the connection is not active in one-minute, some error will be thrown out and the app crashes.
I also ran the same app on the localhost, my MacBook Pro. There was no such problem. It seems to be related to some cleardb specific feature.
Asking for help. And THANKS!