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:
Connect my app running on my local machine to ClearDb's production instance. Works fine.
Connect to ClearDb's production instance via MySql Workbench. Works fine.
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)