-
-
Notifications
You must be signed in to change notification settings - Fork 626
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
Unhandled 'error' event and PROTOCOL_CONNECTION_LOST #1085
Comments
thanks for detail report! Don't have much time to read in details, could you have a look at comments below #683 (comment) |
Hello @sidorares, Well, I think I have an idea why the problem is happening in my situation. Please excuse me if I am wrong, I am not a hardcore nodejs developer, i am fairly new to this amazing world (I come from a C C++ background, I have my own IoT fog middleware) but appears to me that the handlers are not being attached on a connection that does not exist yet (well, at least does not exists from the mysql2 library point of view). What happens is: I setup the pool and, suposedly, I setup the handlers, but on which connection? Then I try to connect, Mysql sends back those packets (which I converted to ascii and are things like the version and something like password). Library code does not acknoledge "if (this._closing) ", it proceeds to:
But nothing was attached to listen to this error, the concept of connection as the library understands is not there yet. Well, this is what I THINK is happening. I think that because the handlers work in connections that were successfully connected at first. But I really do not know If I am right. Regards, |
I've seen this as well Setting the underlying cause of the connection failure aside for a moment.
It looks to me like makeDoneCb is supposed to handle this, but doesn't seem to be. This is my code:
I am trapping any error response from the ping. But in this case, the fatal exception has already caused my code to terminate. Anything I can do differently to prevent this? Or is it a fault with mysql code? |
@ianbale yeah, when you get
Are you saying that |
Doesn't look like it. This is the full error:
Unhandled promise rejection in promise.js:151:22 My code:
I'm catching any error that comes back to me and just deleting my reference to the Db connection so that the next query creates a new one. But it doesn't hit that because the unhandled error exception is thrown upstream from me. FYI: This is in am AWS Lambda function. It can lie dormant for some time - hence I do expect connections to be dropped, but I am doing my best to maintain the connection across invocations where possible. I have the exact same problem with queries that run after an extended period of inactivity. Is there any way to test if the connection has been dropped prior to ping / query? Only other option is for me to drop the connection after the lambda completes and create a new one when the lambda is invoked again. Not as efficient, but should reduce these protocol errors - which are currently causing fatal errors in alive system... |
I've found a few instances of PROTOCOL_CONNECTION_LOST when I am doing queries. In those instances, the error is caught. I do not get the unhandled error exception in promise.js Since they way ping and query are handled in promise.js is the same, I can only conclude that the error is upstream of there. For now I am going to replace my ping with a tiny query. |
@ianbale could you try to set |
That's not going to help me here. Firstly, I am not using pools and secondly, this code is in AWS Lambda. So the code terminates when the call ends, so there is no opportunity for mysql to keep the connection alive until it is invoked again (minimum of every 10 minutes) - which is when I am doing the ping. Variables / state is maintained, so mostly the connection is still ok when it next runs. But sometimes, it's not and the DB connection has been dropped. The issue here is not maintaining the connection, but rather handling the case when the connection has been dropped. So, even if I could use enableKeepAlive, it would, at best, be masking the issue, not resolving it for me. That aside, I have noticed that I was missing an await on the code that called the function where I do the ping. What seems to have been happening is that the code execution was complete and AWS Lambda was spinning down the instance by the time the error is thrown in your library. The upshot is that my error handler appears to have been disabled by the instance pausing. I've added that missing await and have now seen several instances of the same PROTOCOL_CONNECTION_LOST error, but without the unhandled exception error. Upshot - self inflicted by missing the await, compounded by a very misleading error from node.js saying the exception was thrown in promise.js, when in fact, the unhandled exception error was occurring in my code! Thank you for taking the time to look at this and for providing and maintaining this library. It is the core of so much of my work that it's almost forgotten, working its magic under the hood so well. Very much appreciated! |
oh, I suspect missing |
You were too quick! I just edited my comment above having just checked the logs that were produced in the last 30 mins... That was indeed the cause! |
Just in case someone else finds this thread I had an issue with the PROTOCOL_CONNECTION_LOST on my local machine and in github actions and it was just me being too fast. Waiting for 10 seconds or so and then try the connection worked. |
Hello,
First of all, thank you for your work building this amazing library!
I am having the following problem when trying to connect on purpose for testing into a server using an invalid username:
This is how I setup my connection pool:
This is how I attach the error listener, I use the following techniques (tried both):
I have a simple test routine, so everytime I start my nodeJS server, after the pool is created, I run the following:
Now the strange part. I am developing in a Windows 10 machine with MySQL hosted on another machine on the network. This problem “Unhandled 'error' event” does NOT always occur. Sometimes I work for hours and disconnections are handled JUST FINE by the ATTACHED ERROR FUNCTION. I repeat: sometimes the disconnections ARE handled by the handlers!
I don´t know exactly what changes for the behavior appear, but it appears to be after I restart MySQL server.
I decided to turn on the mysql2 library debug, to see what kind of information it shows, during the times the error is happening. Everytime I run my test routine, just before the error, I see this:
I wonder if is there any reason why the emitted error in this situation does not arrive at my error handler?
Thank you!
The text was updated successfully, but these errors were encountered: