NodeJs mysql错误ETIMEDOUT [英] NodeJs mysql error ETIMEDOUT

查看:2545
本文介绍了NodeJs mysql错误ETIMEDOUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NodeJS开发应用程序。



但是,通常服务器会抛出此错误,我无法与mysql交互。



[错误:阅读ETIMEDOUT]
代码:'ETIMEDOUT',
errno:'ETIMEDOUT',
syscall:' read',
fatal:true}
{[错误:在致命错误后无法入队查询]代码:'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR',致命:false}
p>

有人有解决方案来解决这个问题?



感谢

解决方案

从你的问题,我假设你可以与您的数据库完美配合,但是在该连接的给定时间之后经常出现此错误...



假设您正在使用 node-mysql

资料来源: https://github.com/felixge/node-mysql#error-handling

您的错误终止与数据库的连接:


err.fatal:布尔值,表示此错误是否为连接对象的终端。

如果错误不是来自MySQL协议操作,则不会定义此属性。



注意:错误事件是特殊的节点。如果没有
附加侦听器发生,则打印堆栈跟踪,并且您的进程
被杀死。



tl; dr: / strong>此模块不希望您处理静默失败。你
应该总是提供回调方法调用。如果你想要
忽略这个建议并抑制未处理的错误,你可以这样做:




  //我是Chuck Norris:
connection.on('error',function(){});

从此,您可以检查连接状态,并根据需要执行重新连接。






您还可以尝试手动连接到您的mysql服务并更改请求超时:

  wait_timeout:MySQL将在几秒钟内关闭非交互式连接的连接之前等待的秒数。 

http://www.serveridol.com/2012/04/13/mysql-interactive_timeout-vs-wait_timeout/

https:// support .rackspace.com / how-to / how-to-change-the-mysql-timeout-on-a-server /


I'm currently developing an application using NodeJS.

However, often the server throw this error, and I can't interact with mysql.

[Error: read ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'read', fatal: true } { [Error: Cannot enqueue Query after fatal error.] code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false }

Someone has a solution to fixe that ?

Thanks

解决方案

From your question, I assume that you can work with your database perfectly but this error happens often after a given time of that connection being up...

Supposing you are using node-mysql
Source : https://github.com/felixge/node-mysql#error-handling
Your error terminates your connection to the database :

err.fatal: Boolean, indicating if this error is terminal to the connection object.
If the error is not from a MySQL protocol operation, this property will not be defined.

Note: 'error' events are special in node. If they occur without an attached listener, a stack trace is printed and your process is killed.

tl;dr: This module does not want you to deal with silent failures. You should always provide callbacks to your method calls. If you want to ignore this advice and suppress unhandled errors, you can do this:

    // I am Chuck Norris:
connection.on('error', function() {});

From this you could check connection status and perform a reconnect if needed.


You could also try to connect manually to your mysql service and change request timeout :

wait_timeout" : the amount of seconds during inactivity that MySQL will wait before it will close a connection on a non-interactive connection in seconds.

http://www.serveridol.com/2012/04/13/mysql-interactive_timeout-vs-wait_timeout/
https://support.rackspace.com/how-to/how-to-change-the-mysql-timeout-on-a-server/

这篇关于NodeJs mysql错误ETIMEDOUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆