-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connection to database hangs after Error: read ETIMEDOUT #2522
Comments
Hello, and thank you for opening a new issue for this, so I can fix the error handling under that first ticket.
That error is not actually produced from this library, rather it comes from Node.js. It is the representation of a TCP timeout on the system (OS) network stack. When it occurs, the TCP connection is no longer functional. You would need to create a new connection to the database. If you are using the pool, you would do this using
Unfortunately I am not sure. It is poasible the Node.js project may know how, but I unfortunately do not.
This means that you have a reference to a specific connection object in your code. That connection then emitted an error that had the Ideally if you get a fatal error on a connection, you should either call |
Thanks so much for the feedback. I did suspect at one point that loopback-connector-mysql was not properly handling fatal errors, until I realized that when I shut down the database and try to run a query it also returns a fatal error, but works again once I bring the database back up. I wonder if there isn't something unique about this specific error that causes this behaviour. I guess I'll keep investigating. I'll go ahead and close this since there's no evidence the bug is in this library and not in loopback-connector-mysql. Thanks! |
So if it helps at all, though I'm not familiar with the library, and it seems more of a helper library, I noticed based on the stack trace that the Both calls above stack trace as coming from the |
I wonder if it's some sort of corner case in loopback-connector-mysql that's only triggered in very specific situations, maybe even related to the timing of the error. I would settle for being able to reproduce
I've found a similar issue here, in which The thing that gets me is that almost every post I've seen about this mentions using a pool as the solution, which we're already doing. I guess I'll open a bug with loopback-connector-mysql and see what they say. I'm guessing it won't get very far though since I can't reproduce it. Thanks for all of your help! |
I just noticed something that can't be a coincidence; on both nodes the gap between the error and the previous log was almost exactly 8 hours
That makes it seem like it's related to MySQL wait_timeout. In my testing I set it to a very short value, but maybe I set it to a value that was too short... On the other hand, we have Kubernetes readiness probe that runs a |
I'm indirectly using this library via loopback-connector-mysql. By default, that library creates a pool with 10 connections, so any time there is a database issue, my expectation would be that once the database was reachable again, any bad connections would be terminated and the pool would be filled with good connections. This is what I've observed so far in my testing with a local database. If I stop the database, I get errors such as:
Or if I then start up a dummy server that times out connections, e.g.
(https://stackoverflow.com/a/37465639/399105)
I get errors such as:
In both cases (and others I tried), after bringing the database back up, the application was able to reconnect to it without any intervention.
However, in a production application we ran into some errors where the application was hung and would not reconnect to the database until the application was restarted:
(the last error is repeated, I'm guessing for each connection in the pool).
So I have some questions:
Error: read ETIMEDOUT at TCP.onStreamRead
that prevents the pool from reconnecting to the database?Cannot enqueue Query after fatal error.
? My first thought was that the fatal error was a fatal error on the connection itself, but that doesn't seem to be the case as I get a fatal error on the connection when I stop the database, but it comes back up just fine as previously described.Thanks!
The text was updated successfully, but these errors were encountered: