Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: got packets out of order. Expected 6 but received 0 #1753

Open
minhvu7896 opened this issue Dec 20, 2022 · 0 comments
Open

Warning: got packets out of order. Expected 6 but received 0 #1753

minhvu7896 opened this issue Dec 20, 2022 · 0 comments

Comments

@minhvu7896
Copy link

minhvu7896 commented Dec 20, 2022

Hi,
I used mysql2 v2.3.3 (use mysql local) and sometimes I got the following error:

Warning: got packets out of order. Expected 6 but received 0 node:events:491 Emitted 'error' event on Connection instance at: at Connection.protocolError (...\node_modules\mysql2\lib\connection.js:397:10) at Connection.handlePacket (...\node_modules\mysql2\lib\connection.js:445:14) [... lines matching original stack trace ...] at TCP.onStreamRead (node:internal/stream_base_commons:190:23) { fatal: true, code: 4031 }
in db.config:
`

const mysql = require("mysql2");
const bluebird = require("bluebird");

const dbConf = {
  host: "localhost",
  user: "root",
  password: "123456",
  database: "testdb",
  Promise: bluebird,
};

class Database {
  static async getDBConnection() {
    try {
      if (!this.db) {
        // to test if credentials are correct
        await mysql.createConnection(dbConf);
        const pool = mysql.createPool(dbConf);
        // now get a Promise wrapped instance of that pool
        const promisePool = pool.promise();
        this.db = promisePool;
      }
      return this.db;
    } catch (err) {
      console.log("Error in database connection");
      console.log(err.console.error || err);
    }
  }
}

module.exports = Database;

`

in app.js:
`

const getUser = asyn (room) => {
    let conn = await database.getDBConnection();

let [userInRoom] = await conn.query(
      'SELECT testdb.accounts.accountName, testdb.accounts.loginId FROM testdb.userinroom
      JOIN testdb.accounts
      ON testdb.userinroom.accountId = testdb.accounts.id and testdb.userinroom.roomId = ?;',
      room
    );
}

`
I can't find any method to fix it. How can I resolve this error?
Thank you.
Vu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant