1

I'm in the process of getting my React/NodeJS/Express app with a MySql database up and running on Heroku (using free dynos).

I'm using ClearDb ("Punch" licensing level) to host my MySql database in production.

I am using the mysql2 npm package to connect to mysql using connection pools.

I've successfully deployed the app, and can get my login screen to show up in the Heroku staging environment.

When the app tries to run the first query that hits the database, after 10 seconds, I see this message in the logs:

2021-08-30T15:04:44.867293+00:00 app[web.1]: executing DB query
2021-08-30T15:04:54.877125+00:00 app[web.1]: Error: connect ETIMEDOUT
2021-08-30T15:04:54.877132+00:00 app[web.1]:     at /app/server/common/db.js:27:19
2021-08-30T15:04:54.877133+00:00 app[web.1]:     at processTicksAndRejections (internal/process/task_queues.js:95:5)

The query is very simple, and the database barely has any data in the database. The query is running against a table with less than 20 rows in it.

Here is what I've tried:

  1. Connect my app running on my local machine to ClearDb's production instance. Works fine.

  2. Connect to ClearDb's production instance via MySql Workbench. Works fine.

  3. Built a simple health check endpoint that executes the query "select 1". I get the same error in the logs as above.

Here is how I'm connecting (I will be migrating to using SSL for the connection before going live with my app)

    const mysql = require('mysql2/promise')

    const config = {
        host: process.env.DB_HOSTNAME,
        port: process.env.DB_PORT,
        user: process.env.DB_USERNAME,
        password: process.env.DB_PASSWORD,
        insecureAuth : true,
        database: process.env.DB_NAME,
        timezone:'+00:00'
    };

    const pool = mysql.createPool(config)
havab
  • 33
  • 1
  • 5
  • #1 Add a simple endpoint like `/health` on your web to determine if everything is correct. Inside of `/health` perform a simple and classic query validation `select 1`. Execute this endpoint when you detect your error and share us the result. #2 Share us your mysql configuration. #3 Are you using the free cleardb? – JRichardsz Aug 30 '21 at 17:06
  • @JRichardsz, thank you for your reply. I addressed #2 and #3 in my post. I'll work on #1 and report back. – havab Aug 30 '21 at 20:08
  • @JRichardsz published a simple health endpoint using select 1, same result. – havab Aug 30 '21 at 22:13
  • mmm so your app is not connecting to your mysql at most basic level. Try to add the **select 1** at the startup of your server. Just after mysql pool creation. Try to catch the error and share us it – JRichardsz Aug 31 '21 at 01:47

0 Answers0