Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node application: How to increase timeout for mysql2 when debbuging?

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.

like image 656
opike Avatar asked Jun 24 '26 13:06

opike


1 Answers

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)

like image 115
DocMax Avatar answered Jun 27 '26 03:06

DocMax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!