I have an ExpressJS server with Node, running with the MySQL npm package, and all works fine. However, when I leave the server running a long time (say, overnight), I always come back to it having crashed, stating PROTOCOL_PACKETS_OUT_OF_ORDER
. (See below)
How can I fix this, if even at all, as this server is soon to be deployed to production and this will be impossible if it crashes every night.
node:events:505
throw er; // Unhandled 'error' event
^
Error: Packets out of order. Got: 0 Expected: 17
CodePudding user response:
I have the same problem but after I have changed from createConnection to createPool, it won't crash already.
const mysql = require("mysql");
const con = mysql.createPool({
connectionLimit: 5,
host: "localhost",
user: // your user,
password: // your password,
database: // your database,
debug: false
});
con.on("connection", connection => {
console.log("Database connected!");
connection.on("error", err => {
console.error(new Date(), "MySQL error", err.code);
});
connection.on("close", err => {
console.error(new Date(), "MySQL close", err);
});
});
module.exports = con;