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

Timeout Issue despite my Connection Settings Being Correct #2447

Open
gdbjohnson opened this issue Feb 22, 2024 · 1 comment
Open

Timeout Issue despite my Connection Settings Being Correct #2447

gdbjohnson opened this issue Feb 22, 2024 · 1 comment

Comments

@gdbjohnson
Copy link

gdbjohnson commented Feb 22, 2024

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
Copy link
Author

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

mysqljs/mysql#2566

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