Error: Connection lost: The server closed the connection
at Protocol.end (/home/production/project/node_modules/mysql/lib/protocol/Protocol.js:109:13)
at Socket.<anonymous> (/home/production/project/node_modules/mysql/lib/Connection.js:115:28)
at emitNone (events.js:91:20)
at Socket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:934:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
I've been debugging this for a week and found out that if I launch a replica of my server, an empty one with no users, I will still get the same error 12/15 hours approximately after launching it.
Hi @whatthehell232, I understand you are frustrated from the time you spent debugging, but I'm going to bring some bad news in that this is not a bug in this module. The error you are reporting is simply what we provide to you when your MySQL server closes the TCP connection; there is nothing we are going to do and it is your responsibility to react to that error and do whatever your business logic requires, perhaps creating a new connection to your database.
Your MySQL server may close the connection for various different reasons, but the main reason is that you are letting the connection idle (i.e. you opened the connection, perhaps made a few queries, but then didn't close the connection and also didn't make another query within the idle timeout you have defined on your MySQL server).
The wait_timeout variable (https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_wait_timeout) is usually the main thing that defines when a connection has been idle too long, but sometimes it is an intermediate firewall.
I hope this helps!
??? A module that crashes my app when idling has a BUG.
If there's nothing you are going to do, then fuck off. My responsibility to react to this error is to switch to another module, thanks.
If you app is crashing from that, you may want to be sure to read the documentation at https://github.com/mysqljs/mysql#error-handling (or understand how Node.js works and how you do error handling in Node.js). You can also find error handling documentation in Node.js at https://nodejs.org/api/errors.html
I assume that you never attached an error event listener on your connection object, which is why your app is crashing.
Most helpful comment
If you app is crashing from that, you may want to be sure to read the documentation at https://github.com/mysqljs/mysql#error-handling (or understand how Node.js works and how you do error handling in Node.js). You can also find error handling documentation in Node.js at https://nodejs.org/api/errors.html
I assume that you never attached an
errorevent listener on yourconnectionobject, which is why your app is crashing.