Node application crashes due to mysql error 'PROTOCOL_PACKETS_OUT_OF_ORDER'

159
May 31, 2021, at 8:20 PM

I am running a node.js application (web service using express) on RHEL v8, using node v16.1.0.

I recently upgraded the version of mysql used to MySQL Community Server v8.0.24, and ever since have constantly had the application crash due to:

node:events:342 throw er; // Unhandled 'error' event ^

Error: Packets out of order. Got: 0 Expected: 8
    at Parser._tryReadPacketHeader (/home/ec2-user/AGFVB/node_modules/mysql/lib/protocol/Parser.js:470:15)
    at Parser.write (/home/ec2-user/AGFVB/node_modules/mysql/lib/protocol/Parser.js:33:29)
    at Protocol.write (/home/ec2-user/AGFVB/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/home/ec2-user/AGFVB/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.<anonymous> (/home/ec2-user/AGFVB/node_modules/mysql/lib/Connection.js:526:10)
    at Socket.emit (node:events:365:28)
    at Socket.emit (node:domain:470:12)
    at addChunk (node:internal/streams/readable:314:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
Emitted 'error' event on Connection instance at:
    at Connection._handleProtocolError (/home/ec2-user/AGFVB/node_modules/mysql/lib/Connection.js:423:8)
    at Protocol.emit (node:events:365:28)
    at Protocol.emit (node:domain:470:12)
    at Protocol._delegateError (/home/ec2-user/AGFVB/node_modules/mysql/lib/protocol/Protocol.js:398:10)
    at Protocol.handleParserError (/home/ec2-user/AGFVB/node_modules/mysql/lib/protocol/Protocol.js:380:10)
    at Parser._tryReadPacketHeader (/home/ec2-user/AGFVB/node_modules/mysql/lib/protocol/Parser.js:478:10)
    at Parser.write (/home/ec2-user/AGFVB/node_modules/mysql/lib/protocol/Parser.js:33:29)
    [... lines matching original stack trace ...]
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  code: 'PROTOCOL_PACKETS_OUT_OF_ORDER',
  fatal: true
}

An old test environment running on Windows 10 with mysql v5.7 has no issues at all and is stable, so I am currently suspecting a compatibility issue between the versions of node and mysql used - as per https://www.ryadel.com/en/fix-mysql-server-gone-away-packets-order-similar-mysql-related-errors/ (not I have tried setting the max_allowed_packet parameter to 2G as suggested to no avail).

Note that whenever the application connects to the database, it is using code such as:

var mysql = require('mysql');
function createConnection(config){
    try {
        return mysql.createConnection(config);
    } catch(err) {
        console.log("Erorr creating connection: " + err.code);
    }
}
function executeQuery(connection,sql,params,callback){
    try {
        const query = util.promisify(connection.query).bind(connection);
        (async () => {
            try {
                const results = await query(sql, params);
                connection.end();
                callback(results);
            } catch(err) {
                console.log("Error executing query \"" + sql + "\": " + err.code);
                connection.end();
            }
        })();
    } catch(err) {
        console.log("Error executing query \"" + sql + "\": " + err.code);
        connection.end();
    }
}

Note that none of the try/catch blocks are successfully catching the error that is causing the application to crash.

There seem to be a number of other threads reporting the same error code observed, but the issue seems to be very general with a number of possible root causes, so I'm hoping someone may have a better idea given the versions specified and the code used above.

Rent Charter Buses Company
READ ALSO
Javascript and jquery I can&#39;t read value from array index

Javascript and jquery I can't read value from array index

I have a list of numbers (ex"20,145") that returns from an ajax call and I am pushing them to a js array

98
I want to filter the clients of every agent individually. Django

I want to filter the clients of every agent individually. Django

I'm creating a view where I can show all the clients of specific agents via there PK

189
Vue.js disable blank comments

Vue.js disable blank comments

Usually, when Vuejs hides an element through v-if, a comment is left in its place

128
How do I get the correct value in dataframe while webscraping?

How do I get the correct value in dataframe while webscraping?

I am trying to get value from websraping however, I am not able to construct correct class for the value

47