简体   繁体   中英

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.

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 )

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM