Skip to content
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

Throw an error when a connection ends with a RST,ACK packet? #1811

Closed
alejandromav opened this issue Aug 31, 2017 · 13 comments
Closed

Throw an error when a connection ends with a RST,ACK packet? #1811

alejandromav opened this issue Aug 31, 2017 · 13 comments
Assignees
Labels

Comments

@alejandromav
Copy link

According to MySQL docs, COM_QUIT command should end with "either a connection close or a OK_Packet".

As @elemount pointed out in issue #1730, Azure MySQL is answering with an RST,ACK.

It can be reproduced when you run this example code against an Azure MySQL instance.

var mysql      = require('mysql');
var connection = mysql.createConnection({ config });

connection.connect();

connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results[0].solution);
});

connection.end();

Throws ECONNRESET error.

Should this library throw an error when a connection end with a RST with the ACK flag set?
Can we detect this?

@alejandromav alejandromav changed the title Throw an error when a connection end with a RST packet. Throw an error when a connection ends with a RST,ACK packet? Aug 31, 2017
@dougwilson
Copy link
Member

Can you provide the fix or help me setup an Azure MySQL instance to run the code against?

@alejandromav
Copy link
Author

Sure, please give me an email address and I'll send you the connections parameters.

@dougwilson
Copy link
Member

Use the one on my GitHub profile :)

@dougwilson
Copy link
Member

@alex030293 provided a connection to a MySQL Azure instance and I reproduced the issue and have a tentative fix. I should land the fix on master today once I get it cleaned up.

@dougwilson dougwilson self-assigned this Aug 31, 2017
@dougwilson
Copy link
Member

Sorry for the delay, I'm still trying to figure out how to actually make a test for this. It seems like Node.js does not treat a RST as an error unless it thinks it has something to read. It only seems to be an issue with the ACK from the sent data is combined with the RST, but if the ACK and RST are separate Node.js doesn't throw an error. I can't seem to get Node.js code to get them to emit together so far, through, in order to create a test.

@dougwilson
Copy link
Member

@elemount I think in an issue somewhere you said Azure team would be willing to provide a server I can connect the CI of this project to. That would be awesome and definitely help out with this issue, which I cannot figure out how to get a working test for without having an Azure MySQL server in the test suite. Travis CI has the ability to use encrypted secrets in the config, so I can add the credentials to the CI without them being available to the public.

@elemount
Copy link
Contributor

elemount commented Sep 4, 2017

Let me email to him and let he connect with you.

@KalenAnson
Copy link

I have been chasing unhandled ECONNRESET errors related to the mysql library for a while now.

I am getting ECONNRESET unhandled errors from the Connection instance in the file mysql/lib/Connection.js on line 115. The errors look to be related to browser clients that go idle and get reset by the browser. Here is the offending line of code:

this._protocol.on('unhandledError', this._handleProtocolError.bind(this));

The ECONNRESET is a TCP socket event (error), and is handled by Connection._socket. I traced the logic and it appears that the RST packets cause a socket error that eventually bubbles up from the socket object to the protocol object and then back to the Connection instance as an unhandledError event.

What should the Connection instance do when ECONNRESET shows back up as an unhandledError event? It appears that by this point the Protocol queue has been purged and the connection is now in question. It might be nice to close the socket and let the Connection instance emit end rather than emitting an error. Thoughts?

@dougwilson
Copy link
Member

Ok, I got the instructions for how to get the Azure MySQL setup, so I'll work on getting it running in our CI for this issue.

@alejandromav
Copy link
Author

@dougwilson Any update on this? Should we expect this to be fixed in next release? Is there any ETA for next release?

Thanks

@dougwilson
Copy link
Member

I have a failing branch pushed up right now. Still need to get Azure set up and finish the changes. This is what is holding the next release, so yes it is expected in the next release.

@dougwilson
Copy link
Member

Here is the branch if you want to take a look / try: https://github.com/mysqljs/mysql/tree/quit-rst

@dougwilson
Copy link
Member

I merged the change into master now. Please try master and validate that is resolves your issue, when you have a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants