mysqljs / mysql

A pure node.js JavaScript Client implementing the MySQL protocol.
MIT License
18.22k stars 2.53k forks source link

FATAL ERROR: 'PROTOCOL_PACKETS_OUT_OF_ORDER' Got: 0, Expected: 17. #2534

Open Rylxnd opened 2 years ago

Rylxnd commented 2 years ago

I have been having this issue all the time with my server. I just could never find a solution to my probleme. Here is the error I am getting:

events.js:353
      throw er; // Unhandled 'error' event
      ^

Error: Packets out of order. Got: 0 Expected: 17
    at Parser._tryReadPacketHeader (G:\webserver\node_modules\mysql\lib\protocol\Parser.js:470:15)      
    at Parser.write (G:\webserver\node_modules\mysql\lib\protocol\Parser.js:33:29)
    at Protocol.write (G:\webserver\node_modules\mysql\lib\protocol\Protocol.js:38:16)
    at Socket.<anonymous> (G:\webserver\node_modules\mysql\lib\Connection.js:88:28)
    at Socket.<anonymous> (G:\webserver\node_modules\mysql\lib\Connection.js:526:10)
    at Socket.emit (events.js:376:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
Emitted 'error' event on Connection instance at:
    at Connection._handleProtocolError (G:\webserver\node_modules\mysql\lib\Connection.js:423:8)        
    at Protocol.emit (events.js:376:20)
    at Protocol._delegateError (G:\webserver\node_modules\mysql\lib\protocol\Protocol.js:398:10)        
    at Protocol.handleParserError (G:\webserver\node_modules\mysql\lib\protocol\Protocol.js:380:10)     
    at Parser._tryReadPacketHeader (G:\webserver\node_modules\mysql\lib\protocol\Parser.js:478:10)      
    at Parser.write (G:\webserver\node_modules\mysql\lib\protocol\Parser.js:33:29)
    [... lines matching original stack trace ...]
    at Socket.emit (events.js:376:20) {
  code: 'PROTOCOL_PACKETS_OUT_OF_ORDER',
  fatal: true
}

Here is my connection (self made mini sql module):

const mysql = require('mysql')

class Database {
    constructor( config ) {
        this.connection = mysql.createConnection( config )
    }
    query( sql, args ) {
        return new Promise((resolve, reject) => {
            this.connection.query( sql, args, (err, res ) => {
                if (err) {return reject(err);};
                resolve(res)
            })
        })
    }
    end() {
        return new Promise((resolve, reject) => {
            this.connection.end(err => {
                if (err) {return reject(err);}

                resolve()
            })
        })
    }

}

module.exports = Database;

I only ever make one connection. Is this my problem?

Voznov commented 2 years ago

I have the same problem. I set the connection to the base, sent a couple of requests and everything worked. After some time of inaction led to this error. mysql@2.18.1 (github:mysqljs/mysql#3430c513d6b0ca279fb7c79b210c9301e9315658)

how1231 commented 2 years ago

@TheRyGuy2008 I had the same problem. But once I change my connection from mysql.createConnection to mysql.createPool, the error never happen again...