sidorares / node-mysql2

:zap: fast mysqljs/mysql compatible mysql driver for node.js
https://sidorares.github.io/node-mysql2/
MIT License
4.07k stars 619 forks source link

Timeout Issue despite my Connection Settings Being Correct #2447

Open gdbjohnson opened 8 months ago

gdbjohnson commented 8 months ago

I've asked a question on SO on this, but thought I would add one here too.. https://stackoverflow.com/questions/78036167/cannot-connect-timeout-to-mysql-using-nodejs-mysql2-via-ssh-tunnel

I'm trying to run database migrations from Github Actions, on my Aurora RDS instance that is on a private network. In GHA, I created an ssh tunnel via an EC2 jumpbox. Mapping the ports, and using this tunnel, I have used the standard mysql client to connect to it and outputed a query to the console show databases;, and this is successful. So: the tunnel works, and nothing is blocking the connection from either side.

From NodeJS, using mysql2, I'm getting a timeout. I don't understand what I need to do, to figure out how to solve it.

Here's the connection:

function getConnection() {
    return new Promise((resolve, reject) => {
        const connection = mysql.createConnection({
            host: process.env.DB_HOST,
            port: process.env.DB_PORT,
            user: process.env.DB_USER,
            password: process.env.DB_PASSWORD,
            database: process.env.DB_NAME
        });

        resolve(connection);
    });
}

Here's the config:

DB_HOST=127.0.0.1
DB_PORT=3307
DB_NAME=booking
DB_USER=admin
DB_PASSWORD=<secret>

And here's the tunnel:

- name: Open SSH Tunnel
        run: |
          echo -n "${{env.KEY}}" > github.pem
          sudo chmod 600 github.pem
          ssh -f -N -L 3307:${{env.DB_HOST}}:3306 ${{env.USER}}@${{env.HOST}} -i ./github.pem -o StrictHostKeyChecking=no
          nc -zv localhost 3307
          mysql -h 127.0.0.1 -P 3307 -u ${{env.DB_USER}} -p${{env.DB_PASSWORD}} -e "SHOW DATABASES;"

See anything I don't? What can I do to understand the root cause?

gdbjohnson commented 8 months ago

Is this issue related to this one? This describes my issue almost exactly...

https://github.com/mysqljs/mysql/issues/2566