MySQL Connection Timeout (ETIMEDOUT) Causes Crash When DB Becomes Unresponsive
Kutt crashes with a connect ETIMEDOUT error when the external MySQL database becomes unresponsive. The server initially starts fine, but if the database stops responding while Kutt is running, the application crashes instead of handling the disconnection gracefully.
Here’s the full error message:
> [email protected] start
> node server/server.js --production
> Ready on http://localhost:3100
Connection Error: Error: read ECONNRESET
Connection Error: Error: read ECONNRESET
/home/iroak/Kutt/node_modules/mysql2/lib/base/connection.js:200
const err = new Error('connect ETIMEDOUT');
^
Error: connect ETIMEDOUT
at Connection._handleTimeoutError (/home/iroak/Kutt/node_modules/mysql2/lib/base/connection.js:200:17)
at listOnTimeout (node:internal/timers:581:17)
at process.processTimers (node:internal/timers:519:7) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
}
Steps to Reproduce
- Start Kutt:
cd /home/iroak/Kutt && npm run start - The server initializes successfully and prints
Ready on http://localhost:3100. - While Kutt is running, the external MySQL database temporarily stops responding.
- Kutt crashes with the
ETIMEDOUTerror instead of retrying the connection or handling the failure gracefully.
Expected Behavior
Kutt should handle temporary database disconnections more gracefully, either by retrying the connection or logging an error without crashing.
Actual Behavior
When the external database becomes unresponsive, Kutt crashes with a fatal connect ETIMEDOUT error. This makes it necessary to restart the service manually.
System Info
- Kutt Version: 3.2.2
- Node.js Version: 20.18.3
- Database: External MySQL
- Operating System: Linux
Additional Context
- The database sometimes experiences temporary connection issues but eventually recovers.
- Other applications connected to the same MySQL instance do not crash when the database goes down.
- The
.envfile contains the correct database credentials.
Would it be possible to add a reconnection mechanism or error handling to prevent crashes when the database is temporarily unavailable?
It does retry making a connection again but it exceeds the timeout threshold.
Maybe you can increase timeout: https://knexjs.org/guide/#acquireconnectiontimeout