I occasionally encounter the following error, leading to a server crash. The crashes appear to coincide with the wait_timeout, occurring approximately every 8 hours. Apart from this issue, all other functionalities operate as anticipated. Despite extensive online research, I have been unable to find a resolution for this issue.
{
"name": "Error",
"stack": "Error: Packets out of order. Got: 0 Expected: 10\n at Parser._tryReadPacketHeader (/home/ec2-user/drogoserver/node_modules/mysql/lib/protocol/Parser.js:470:15)\n at Parser.write (/home/ec2-user/drogoserver/node_modules/mysql/lib/protocol/Parser.js:33:29)\n at Protocol.write (/home/ec2-user/drogoserver/node_modules/mysql/lib/protocol/Protocol.js:38:16)\n at Socket. (/home/ec2-user/drogoserver/node_modules/mysql/lib/Connection.js:88:28)\n at Socket. (/home/ec2-user/drogoserver/node_modules/mysql/lib/Connection.js:526:10)\n at Socket.emit (node:events:513:28)\n at Socket.emit (node:domain:489:12)\n at addChunk (node:internal/streams/readable:315:12)\n at readableAddChunk (node:internal/streams/readable:289:9)\n at Socket.Readable.push (node:internal/streams/readable:228:10)",
"message": "Packets out of order. Got: 0 Expected: 10"
}
This is how i create the pool:
const pool = mysql.createPool({
host: "",
port: "3306",
user: "",
password: "",
database: "",
charset: "utf8mb4",
multipleStatements: true,
connectionLimit: 100,
acquireTimeout: 1000000,
connectTimeout: 30000,
});
module.exports = pool;
In some parts of the application i use db.query(pool.query) or db.getConnection then perform the query and release the connection.
For example there are so many such cases like:
function someBigFunction(){
db.getConnection(async function (err, connection) {
if (err) throw err;
await someFunctionQueryingUsingConnection(connection)
await someOtherFunctionQueryingUsingConnection(connection)
connection.release()
})
}
function someFunctionQueryingUsingConnection(connection) {
return new Promise(function (resolve, reject) {
connection.query(
query,
queryParameterList,
async function (error, results, fields) {
resolve(results)
})
})
}
I am using AWS RDS MySQL service. Some parameters are:
wait_timeout 28800
interactive_timeout 28800
max_allowed_packet 500000000
version "mysql2": "^3.7.0",
I'm truly desperate for assistance with this issue.
Thanks
If you are facing with this issue check if there is any library opening a connection and not closing it. In my case i was using some wrapper for deadlocks and it left an open connection which caused this problem.