MySQL gives the error "read ECONNRESET" after downtime on the node.js server

I am starting a Node server connecting to MySQL through the node -mysql module. However, connecting to and querying MySQL is very good, but there are no errors; however, the first query after exiting the Node server for several hours leads to an error. The error is the familiar read ECONNRESET , coming from the depths of the node-mysql module.

Stack Trace (note that the three trace entries relate to my application error report):

 Error at exports.Error.utils.createClass.init (D:\home\site\wwwroot\errors.js:180:16) at new newclass (D:\home\site\wwwroot\utils.js:68:14) at Query._callback (D:\home\site\wwwroot\db.js:281:21) at Query.Sequence.end (D:\home\site\wwwroot\node_modules\mysql\lib\protocol\sequences\Sequence.js:78:24) at Protocol.handleNetworkError (D:\home\site\wwwroot\node_modules\mysql\lib\protocol\Protocol.js:271:14) at PoolConnection.Connection._handleNetworkError (D:\home\site\wwwroot\node_modules\mysql\lib\Connection.js:269:18) at Socket.EventEmitter.emit (events.js:95:17) at net.js:441:14 at process._tickCallback (node.js:415:13) 

This error occurs both on my Node cloud server and on the MySQL server, as well as on the local configuration of both.

My questions:

  • Is this a problem disconnecting the Node connection to my MySQL server, possibly due to a limited connection life?

  • When using connection pools, node-mysql should gracefully handle disconnections and trim them from the pool. Is it not known about disconnecting until I make a request, making the mistake inevitable?

  • Given that I often see the "read ECONNRESET" error in other StackOverflow posts, should I look elsewhere from MySQL to diagnose the problem?

Update:. After looking more, I think my problem is a duplicate of this . It seems that his connection is also disconnected, but no one suggested how to keep the connection alive or how to fix the error outside the failure on the first request.

+4
source share
3 answers

I turned to node-mysql people on their Github page and got some solid answers.

  • MySQL really disables downtime. There MySQL variable "wait_timeout", which sets the number of seconds before the timeout, and the default value is 8 hours. We can set the default much more. Use show variables like 'wait_timeout'; to view the timeout settings and set wait_timeout=28800; to change it.

  • According to this problem , node-mysql does not cut pool connections after these kinds of disconnections. The developers of the modules recommended using a pulse to maintain the connection, for example, calling SELECT 1; on the interval. They also recommended using the node -pool module and its idleTimeoutMillis to automatically turn off downtime.

+5
source

Is this a problem disconnecting the Node connection to my MySQL server, possibly due to a limited connection life?

Yes. The server has closed its end of the connection.

When using connection pools, node-mysql should gracefully handle disconnections and trim them from the pool. Is it not known about disconnecting until I make a request, making the mistake inevitable?

That's right, but it should handle the error inside, and not pass it on to you. This seems to be a bug in node-mysql. Report this.

Given that I see the "read ECONNRESET" error in other StackOverflow posts, should I look elsewhere from MySQL to diagnose the problem?

This is either an error in the connection pool of the node-MySQL pool, otherwise you incorrectly configured it to detect failures.

+1
source

If this occurs when a single reusable connection is established, it can be avoided by installing a connection pool instead.

For example, if you do something like this ...

 var db = require('mysql') .createConnection({...}) .connect(function(err){}); 

do it instead ...

 var db = require('mysql') .createPool({...}); 
0
source

All Articles