简体   繁体   English

节点应用程序:调试时如何增加mysql2的超时时间?

[英]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. 我在Web应用程序中使用mysql2节点程序包(v1.2.0),当我使用调试器(使用webstorm)单步执行代码时,如果我在某些断点处坐的时间太长,则启动连接有时会超时。

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 . 如果超时在客户端上,则连接超时的属性为connectTimeout ,而不仅仅是timeout The documentation for the (compatible) mysql package reads: (兼容)mysql软件包的文档内容如下:

connectTimeout : The milliseconds before a timeout occurs during the initial connection to the MySQL server. connectTimeout :与MySQL服务器的初始连接期间发生超时之前的毫秒数。 (Default: 10000 ) (默认值: 10000

MySQL has it's own timeout as well. MySQL也有它自己的超时。 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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