我在 MySql 中使用 Loopback。我在运行时随机出现以下错误
nodemon .
或
node .
Web server listening at: http://0.0.0.0:3000 Browse your REST API at http://0.0.0.0:3000/explorer Connection fails: Error: connect ETIMEDOUT It will be retried for the next request. events.js:160 throw er; // Unhandled 'error' event ^ Error: connect ETIMEDOUT at PoolConnection.Connection._handleConnectTimeout
- 我该如何解决这个问题?在 Loopback 端配置或 MySQL 配置?注意:我正在为 MySQL 使用 MAMP。
- 需要很长时间才能成功启动而不出错。什么 我应该如何快速重启?
最佳答案
这似乎是 MySQL 和 Loopback 的一个已知问题,它会导致在 Loopback 首次启动时连接在重负载下超时:
https://github.com/strongloop/loopback-connector-mysql/issues/210
一些可能的解决方案:
如果您在 VM 或容器上运行,增加 CPU 资源可能会解决问题。
在数据源配置中设置
connectTimeout
和acquireTimeout
(根据需要调整值):{ "mySQL":{ //... "connectTimeout": 20000, "acquireTimeout": 20000 }
( https://github.com/strongloop/loopback-connector-mysql/issues/210#issuecomment-258089303 )
这是另一种选择:
Our solution was to remove the initial database connection from the loopback boot by enabling lazyConnect in the datasource config, and then to separately call the datasource connection after the boot is finished. We came to a similar conclusion that CPU stress during the loopback boot causes the db connection to fail.
( https://github.com/strongloop/loopback-connector-mysql/issues/210#issuecomment-758091028 )
关于mysql - 连接失败 : Error: connect ETIMEDOUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39861042/