6

I'm using the mysql2 node package (v1.2.0) in a web application and when I'm stepping through the code using the debbugger (using webstorm), if I sit too long at certain breakpoints, initiating the connection will sometimes time out.

Here's the message I receive when it times out:

Error: connect ETIMEDOUT
    at Connection._handleTimeoutError (/Volumes/github-image/bitcoin-core/node_modules/mysql2/lib/connection.js:179:13)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

I was hoping to increase the timeout to avoid this issue. I tried adding a custom timeout value for when the connection is set up.

export const connection = mysql.createConnection({
  host: dbHost,
  user: dbUser,
  password: dbPassword,
  database: dbName,
  timeout: 60000
});

But this had no effect.

opike
  • 7,053
  • 14
  • 68
  • 95

2 Answers2

5

If the timeout is on the client, the property for the connection timeout is connectTimeout, not just timeout. The documentation for the (compatible) mysql package reads:

connectTimeout: The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10000)

DocMax
  • 12,094
  • 7
  • 44
  • 44
1

MySQL has it's own timeout as well. You can modify it likeso (from here)

con.query('SET GLOBAL connect_timeout=28800')
con.query('SET GLOBAL wait_timeout=28800')
con.query('SET GLOBAL interactive_timeout=28800')
vfioox
  • 730
  • 1
  • 8
  • 22