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

Connection closed exceptions after migration from mysql.data to mysql connector #661

Closed
tomekpr opened this issue Jun 27, 2019 · 5 comments
Labels
waiting for answer Needs more information from the bug reporter

Comments

@tomekpr
Copy link

tomekpr commented Jun 27, 2019

Hi,

I hope someone can advise on the following problem. I have a windows service that I'm trying to migrate from Mysql.Data to mysqlconnector-net. With other services the process was fairly smooth but the target databases arent under high load.

After the upgrade, I've started to notice exceptions like the following one: 'System.InvalidOperationException: Connection must be Open; current state is Closed'

The database server is quite busy, a lot of connections open and I can see that some insert operations take 20s. This is expected. This is our test environment and the RDS instance is quite small. I'm guessing that the sql-related operations just take a lot of time, connections are closed in the meantime and I end up with this problem.

What I don't understand is why am I seeing these exceptions after upgrade ? Connection count hasn't really changed and default values for command timeouts and connection timeouts seem to be the same when I compare mysql.data and mysqlconnector.

Thanks,
TP

@tomekpr
Copy link
Author

tomekpr commented Jun 27, 2019

Hi,

Just an update to the above case. I've just noticed that on upper environments I also saw similar errors with mysql.data so I wouldn't attribute this problem to the mysql-connector. It's time for some additional code-review.

@bgrainger
Copy link
Member

If you're using async code (e.g., ExecuteReaderAsync), MySqlConnector can expose a new class of errors, because it actually implements these methods with real async I/O. (MySql.Data just fakes it.)

It would be helpful to see the full exception call stack, but I'm guessing it's possible a MySqlConnection object is getting shared between two threads, and getting closed on one while another is still using it. This is not allowed by the API.

It may help to enable debug-level logging and see if that provides any clues: https://mysqlconnector.net/overview/logging/

@bgrainger bgrainger added the waiting for answer Needs more information from the bug reporter label Jun 29, 2019
@tomekpr
Copy link
Author

tomekpr commented Jul 3, 2019

The timeouts are happening when the connection (session) is reset between uses, one option is to disable the connection reset its just a connection string change add ConnectionReset=false

@tomekpr tomekpr closed this as completed Jul 3, 2019
@bgrainger
Copy link
Member

The error message is the same as #667. Can you post the full call stack from when this happens, so I can see if it's the same bug?

@tomekpr
Copy link
Author

tomekpr commented Jul 5, 2019

Sure,

2019-06-27 10:03:16,080|ERROR|Betgenius.InRunning.GameServer.Host.Adaptors.Persistence.MySql.ReadSide.MySqlGameEventReadSidePersistor|12| Error when attempting to persist event Betgenius.InRunning.Common.DomainModel.Events.MarketSetOnlineEvent to MySqlReadSide :server=test;uid=testuser;pwd=testpass;database=GameState;SslMode=none;UseCompression=False;maxpoolsize=15 Connection state: Closed System.InvalidOperationException: Connection must be Open; current state is Closed
   at MySql.Data.MySqlClient.MySqlConnection.get_Session() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 422
   at MySql.Data.MySqlClient.MySqlCommand.ResetCommandTimeout() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 389
   at MySql.Data.MySqlClient.MySqlCommand.<ExecuteNonQueryAsync>d__61.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 276
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 77
   at Betgenius.InRunning.GameServer.Host.Adaptors.Persistence.MySql.ReadSide.MySqlGameEventReadSidePersistor.SaveIndividualEvent(GameKey gameKey, IGameEvent gameEvent, MySqlConnection connection, Guid correlationId, OperationTimingContext operationTimingContext)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for answer Needs more information from the bug reporter
Development

No branches or pull requests

2 participants