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
Infinite waiting on closing connection using ClearDB on Azure #330
Comments
I think That's on my list for 1.0 but I'm not sure when I'll get to it. Ideally, we would simulate the different server behaviours with a "fake" server (#271) to have a high degree of confidence that the client behaves correctly in different scenarios. |
@ktos, regarding this specific problem, do you think it would be fixed by removing the single line that waits for a response after sending a
MySQL Server 5.7 doesn't actually send an |
MySQL Server 5.7 does not send OK payload after QUIT command, but simply closes the TCP connection, so this wait is unnecessary. Also fixes mysql-net#330, in which case there was an infinite waiting.
Yes, it is also solving my issue. I've prepared a beautiful one-line PR #335 for this (if really just removing this one line is everything) :-) |
Fixed in 0.26.5. |
Hi, I have a problem using ClearDB on Azure with Pomelo.EntityFrameworkCore (PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#384), and I debugged it more thoroughly, and unfortunately it seems it's MySqlConnector problem so I am bringing it here.
Too long, don't want to read? See lower ;)
I've debugged it in Pomelo.EntityFrameworkCore that it starts in getting server version, actually in line 42, which is closing the connection. So I've replicated it into a small .NET Core 2.0 console app:
So you see it's just connecting, reading server version and disconnecting. And it does not work with ClearDB and MySqlConnector freshly downloaded from GitHub. I've tried two ClearDB regions (West Europe and North Europe) and two plans (free and the cheapest one). Same issue.
In closing the connection (used here explicitely for debugging) I have a situation that there is an infinite wait (I have waited over 3 minutes) for closing the connection. It seems that the problem is here: https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/MySqlClient/MySqlConnection.cs#L392 - this line waits.
Going inside we are in https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/Serialization/MySqlSession.cs#L171-L173 and the problem is in ReadPayloadAsync. The quit command seems to be sent correctly - I have wireshark dumps in the previous issue attached.
Let's look at the stacktrace:
So we're at https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/Protocol/Serialization/BufferedByteReader.cs#L16 and m_remainingdata.Count is 0 while count is 4. This of course goes to https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/Protocol/Serialization/BufferedByteReader.cs#L37 and then to https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/Protocol/Serialization/SocketByteHandler.cs#L22 because
ioBehavior
is Synchronous.And this
m_stream.Read()
stays here forever.I've searched the web and think that maybe the problem is similar to npgsql/npgsql#265 - I think ClearDB's MySQL is just closing the connection after quit command (see again how does it look like in wireshark) and there is no data to be received.
To solve this we could possibly use ReadTimeout?
ReadTimeout property for m_stream in https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/Protocol/Serialization/StreamByteHandler.cs#L18 is -1 (indefinite), so I've changed it into 100 ms for test. That causes IOException, which is being caught in https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/Serialization/MySqlSession.cs#L175 (and nothing happens).
I've changed that to be more polite and disconnect the socket on IOException:
And run my app again. It throws IOException and it works! Then, I've started the actual app using EF and it also works now! Both on Azure's ClearDB and on my local MySQL server.
But it does not work when I had
Ssl Mode=none
in my ConnectionString.So I've removed ReadTimeout in StreamByteHandler and I've added in https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/Protocol/Serialization/SocketByteHandler.cs#L11
m_socket.ReceiveTimeout = 500;
. And it works now for both SSL and non-SSL connection!TL;DR: It seems ClearDB is closing the connection just after quit command while MySqlConnector is still waiting for something. Adding ReceiveTimeout for socket seems to fix it.
I would be happy to prepare a PR for this, but:
The text was updated successfully, but these errors were encountered: