sidorares / sidorares/node-mysql2
Connection Timeout on ubuntu 22.04 (works fine on windows)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
Hello,
I'm encountering a connection timeout issue on Ubuntu,
the exact same code works flawlessly on Windows
I'm new to ExpressJS and am trying to create an API using mysql2
I have checked all firewalls, ports, etc., but I'm still facing this problem. i mean It's working on Windows for some reason but not on Ubuntu.
Node.js Version: v20.15.0 on both systems
mysql2: v3.10.2
Database: MariaDB (connecting to the same database on both Windows and Ubuntu)
Error:
Listening on port: 4300
Error connecting to the database: Error: connect ETIMEDOUT
at PoolConnection._handleTimeoutError (/root/api/node_modules/mysql2/lib/connection.js:205:17)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
}
Connection code
(async () => {
try {
const connection = await pool.getConnection();
console.log("Connected to the database");
connection.release();
} catch (err) {
console.error("Error connecting to the database:", err);
process.exit(1);
}
})();
database file
import dotenv from 'dotenv';
import mysql from 'mysql2/promise';
dotenv.config();
const pool = mysql.createPool({
host: process.env.HOST,
user: process.env.USER,
password: process.env.PASSWORD,
database: process.env.DATABASE
});
export default pool;
The code is straightforward, I don't understand why it will have problems on Ubuntu.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the Ubuntu and Windows connection environments using the shown database file and pool.getConnection() entry point, including the HOST, USER, PASSWORD, and DATABASE values. Reproduce the ETIMEDOUT error and identify a verified Ubuntu-specific cause; the issue currently names no project test or source file beyond the example configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, javascript, mariadb, node.js
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100