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.

Warning: got packets out of order

See original GitHub issue

Hi,

I’m trying to combine the node-mysql2 and ssh2 modules so that I can connect to the database via ssh. Something similar to this:

https://stackoverflow.com/questions/30658906/trouble-connecting-to-mysql-via-ssh/30669454#30669454

Everything is working as expected. However, if I try to run several queries concurrently, then I get a got packets out of order warning and eventually an error.

Here is some code that will reproduce the issue:

db.js

'use strict';

const Bluebird = require('bluebird');
const Mysql = require('mysql2/promise');

module.exports = function (stream) {

    const connectionOptions = {
        host: 'localhost',
        user: 'root',
        password: 'YOUR_PASSWORD',
        database: 'YOUR_DB',
        connectionLimit: 10,
        dateStrings: true,
        decimalNumbers: true,
        timezone: 'Z',
        supportBigNumbers: true,
        stream: stream,
        Promise: Bluebird
    };

    const pool = Mysql.createPool(connectionOptions);

    function getSqlConnection() {

        return pool.getConnection().disposer(function (connection) {

            return connection.release();
        });
    }

    return {
        query(sqlString, values) {

            return Bluebird.using(getSqlConnection(), function (connection) {

                return connection.query(sqlString, values);
            });
        },
        closeAllConections() {

            return pool.end(function (err) {

                if (err) {
                    console.log(err);
                }
            });
        }
    };
};

index.js

'use strict';

const _ = require('lodash');
const Bluebird = require('bluebird');
const SshClient = require('ssh2').Client;

const ssh = new SshClient();

function runDbQueries() {

    return new Bluebird(function (resolve, reject) {

        ssh.on('ready', function () {

            ssh.forwardOut(
                '127.0.0.1',
                12345,
                '127.0.0.1',
                3306,
                function (err, stream) {

                    if (err) {
                        return reject(err);
                    }

                    const Db = require('./db.js')(stream);

                    const promises = _.map(_.range(5), function (n) {

                        return Db.query('Select * from `users`', []);
                    });

                    return resolve(Bluebird.all(promises));                            
                }
            );
        });

        ssh.connect({
            host: '127.0.0.1',
            username: 'vagrant',
            agent: process.env.SSH_AUTH_SOCK
        });
    });
}

runDbQueries()
    .then(function (results) {

        console.log(results);
    })
    .catch(function (error) {

        console.log(error);
    });

If I run the queries in series, then the code works just fine. Also, I have similar code running without the ssh2 requirement, and the concurrent queries run without problems there.

Any help would be appreciated. Thanks.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:6
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jchapellecommented, Aug 24, 2022

I encounter the same error. I configured a connectionLimit of 40.

‘got packets out of order’ happens during handhsake when driver sends hello packet to existing opened connection

What does that means ? The driver sends hello packet to a connection which is used by somebody else ? How to avoid this ?

1reaction
dietrichgcommented, Aug 12, 2022

Getting this error still. I had my localhost sitting for about 12 hours and it randomly go this error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: got packets out of order. Expected 10 but received 0 ...
This happens for us when using connection pool and server sends ER_CLIENT_INTERACTION_TIMEOUT packet (new from MySQL 8.0.24). To reproduce, set wait_timeout and ...
Read more >
Error: Packets out of order. Got: 1 Expected: 0 - Stack Overflow
I found the Problem. After using the npm package mysql2 I got the error message: "Too many connections". I dumbly initialized my class...
Read more >
MySQL: Packets out of order error - General - Node-RED Forum
Hi everyone, I have an issue when I'm creating a table via mysql. When I'm sending the query, the first time is ok...
Read more >
how can I fix: Packets out of order. Expected 0 received 1 ...
how can I fix: Packets out of order. Expected 0 received 1. Packet size=68. I installed Laravel in a shared hosting, I placed...
Read more >
Packets out of order. Expected 1 received 0. Packet size=145
Hi, I use backwpup 3.8.0 on WP 5.7.2 and both scheduled and manual jobs shows: “WARNING: Packets out of order. Expected ...
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