node-mysql2: ECONNRESET
I get these errors sometimes. Randomly.
Error: read ECONNRESET
at exports._errnoException (util.js:742:11)
at TCP.onread (net.js:535:26)
and
Error: write ECONNRESET
at exports._errnoException (util.js:742:11)
at Object.afterWrite (net.js:749:14)
I read somewhere that this also happens on node-mysql
, but that it could be fixed by using pool. I began using pool, but it still happens.
Suggestions?
About this issue
- Original URL
- State: open
- Created 10 years ago
- Comments: 27 (10 by maintainers)
for anyone getting this error randomly. i guess you’re supposed to write this wrapper around
pool.query
(or whatever call you’re using). stops the problem for me.For one I agree that this driver should have a ‘keep alive’ option. It’s hard to debug and there are no ‘using’ keyword like c# that makes it easy o handle in JavaScript
Thursday, January 10, 2019, 6:42 PM -0500 from notifications@github.com notifications@github.com:
@sidorares you don’t seem surprised that this causes random errors on production servers. shouldn’t the library do some kind of error catching retries before throwing an error? or is everyone supposed to write custom wrapper code to do that themselves? (i missed the memo) or is computer software just supposed to have some errors?
Very late to the discussion, but @benbotto could you please tell me how you solved this issue finally? I wasn’t able to find any proper solutions on the internet.
I’m sorry to wake the dead here, but I’m struggling to fix this in my code as well. It has caught me by surprise after deploying to production, which isn’t the ideal time to encounter the error.
MySQL has a
wait_timeout
which is 8 hours by default. If no queries run against a connection in that 8-hour time frame, MySQL evidently terminates the connection. Is my understanding correct in that this library’s connection pool does not handle those terminations and blindly attempts to reuse the terminated connections? Is it not possible for the library to establishing new connections when the server closes idle ones? I see farzher’s code snippet (and thanks for that!), but is there a more keep-alive type solution that can be used as a workaround? I’ve seen some people using aSELECT 1
-on-an-interval approach, but I don’t understand how that will keep all of the connections in a pool alive.I see this in the MySQL documentation, but it doesn’t seem to be the case for mysql2:
Thanks for the support.
@sidorares that’s fair. maybe make mention that in the readme so lazy people like me are reminded to do proper error handling.
i’m using a pool, you can see the error is
at PromisePool.query mysql2/promise.js:323
getting this sometimes randomly. simple test server, nothing complex happening on it.