'Error: Packets out of order. Got: 1 Expected: 0

All the Solutions I found for this Problem don't work for me. I'm just loading one Dataset and after approximate 150 Request I get this Error:

Error: Packets out of order. Got: 1 Expected: 0
at Parser._tryReadPacketHeader (C:\dev\node\webkoll\node_modules\mysql\lib\protocol\Parser.js:470:15)
at Parser.write (C:\dev\node\webkoll\node_modules\mysql\lib\protocol\Parser.js:33:29)
at Protocol.write (C:\dev\node\webkoll\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\dev\node\webkoll\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (C:\dev\node\webkoll\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:223:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:181:23)
--------------------
at Protocol._enqueue (C:\dev\node\webkoll\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\dev\node\webkoll\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\dev\node\webkoll\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\dev\node\webkoll\node_modules\mysql\lib\Pool.js:48:16)
at C:\dev\node\webkoll\dbHelper.js:35:22
at new Promise (<anonymous>)
at dbHelper.execQueryWithParams (C:\dev\node\webkoll\dbHelper.js:34:16)
at dbHelper.loadFinishedResultFlag (C:\dev\node\webkoll\dbHelper.js:68:21)
at C:\dev\node\webkoll\index.js:321:30
at Layer.handle [as handle_request] (C:\dev\node\webkoll\node_modules\express\lib\router\layer.js:95:5) {  code: PROTOCOL_PACKETS_OUT_OF_ORDER',  fatal: true}

I'm using node v12.14.1 and the npm package mysql v2.18.1. I also set the max_allowed_packet to 1G but it did not help.

Here the Code i use to get the data:

class dbHelper {
constructor() {
    const { host, user, password, database, connectionLimit } = config.db;
    this.con = mysql.createPool({
        connectionLimit,
        host,
        user,
        password,
        database
    });
}

async execQueryWithParams(query, params) {
    return new Promise((resolve, reject) => {
        this.con.getConnection((err, connect) => {
            if (err) {
                console.log(err);
                return reject(err)
            }
            connect.query(query, [params], (err, result) => {
                if (err) {
                    return reject(err);
                }
                resolve(result);
            })
        })
    });
}


Solution 1:[1]

I found the Problem.

After using the npm package mysql2 I got the error message: "Too many connections".

I dumbly initialized my class way to often, so after using just one instance everything worked fine.

Solution 2:[2]

Try to increase the MAX_Packet_Allowed Memory - it works in my case

Solution 3:[3]

It can be - your pool connection is lost. Try checking wether it is still up.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Reazilus
Solution 2 kashish
Solution 3 Alben Evstontiev