kutt icon indicating copy to clipboard operation
kutt copied to clipboard

MySQL Connection Timeout (ETIMEDOUT) Causes Crash When DB Becomes Unresponsive

Open iiroak opened this issue 10 months ago • 1 comments

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

  1. Start Kutt:
    cd /home/iroak/Kutt && npm run start
    
  2. The server initializes successfully and prints Ready on http://localhost:3100.
  3. While Kutt is running, the external MySQL database temporarily stops responding.
  4. Kutt crashes with the ETIMEDOUT error 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 .env file 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?

iiroak avatar Mar 04 '25 01:03 iiroak

It does retry making a connection again but it exceeds the timeout threshold.

Maybe you can increase timeout: https://knexjs.org/guide/#acquireconnectiontimeout

poeti8 avatar Mar 06 '25 08:03 poeti8