question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fatal `Packets out of order` exception using `mysql` lib connecting to `mysql2` proxy

See original GitHub issue

Using the example proxy, when making a client connection using the mysql library, a fatal exception occurs and the connection is lost.

Client example:

const knex = require("knex")({
  client: "mysql",
  connection: {
    host: "127.0.0.1",
    port: 4000,
    user: "***",
    password: "***",
    database: "***"
  },
});

knex.raw("select 1").then(console.log);

The server exception:

[nodemon] starting `node index.js`
connection
Warning: got packets out of order. Expected 3 but received 0
proxying query: select 1
events.js:298
      throw er; // Unhandled 'error' event
      ^

Error: Connection lost: The server closed the connection.
    at Socket.<anonymous> (/foo/node_modules/mysql2/lib/connection.js:91:31)
    at Socket.emit (events.js:321:20)
    at TCP.<anonymous> (net.js:668:12)
Emitted 'error' event on Connection instance at:
    at Connection._notifyError (/foo/node_modules/mysql2/lib/connection.js:221:12)
    at Socket.<anonymous> (/foo/node_modules/mysql2/lib/connection.js:97:12)
    at Socket.emit (events.js:321:20)
    at TCP.<anonymous> (net.js:668:12) {
  fatal: true,
  code: 'PROTOCOL_CONNECTION_LOST'
}

Client exception:

(node:1521) UnhandledPromiseRejectionWarning: Error: Packets out of order. Got: 4 Expected: 1

NOTE: This does not occur when using mysql2 as the client library.

Please let me know if I can provide any further detail to help debug.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

0reactions
dtikhonov-iexcommented, Sep 27, 2022

Thanks for this workaround, @MartinGassner. I was hoping that the bug was something obvious (and I spent some time reading the code trying to figure it out), but from @sidorares’s description it seems that this is a structural issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

got packets out of order. Expected 1 but received 28 · Issue ...
I am trying to create a MySQL server using node-mysql2, ... Fatal Packets out of order exception using mysql lib connecting to mysql2...
Read more >
4.22 Troubleshooting Problems Connecting to MySQL
You can fix this by setting up an account for the combination of client host name and user name that you are using...
Read more >
"MySQL server has gone away" error - Solution(s)
The MySQL server has gone away error, which means that the MySQL server (mysqld) timed out and closed the connection. By default, MySQL...
Read more >
Fix "MySQL server has gone away", "packets out of order" ...
The issue might be due to the fact that the server timed out and closed the connection. Check the wait_timeout MySQL variable value...
Read more >
Error: Packets out of order. Got: 0 Expected: 3 - mysql
I'd suspect the mysql-nodejs version isn't resetting the expected packet count on re-connection. In a test environment you can reduce the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found