Net packets out of order on opening a connection with connection pooling?
Posted: Thu 07 Mar 2019 20:01
Here is our connection string:
pooling=true;server=192.168.1.100;database=dbname;uid=dbuser;pwd=dbpwd;
Sometimes, very infrequently and when the system is under load, we will get errors like "Net packets out of order - expect [X], received [Y]", or similar.
I have done a little reading on the forums and was hoping some of the advice I found could be clarified. Specifically, at the bottom of the first page of this post: viewtopic.php?t=6396
1. Make sure you close all data readers explicitly.
In .NET, we sometimes explicitly call the Close method on the MySqlDataReader and sometimes we just open the MySqlDataReader in a Using block without explicitly invoking the Close method. I am guessing that the Dispose method of MySqlDataReader which Using calls when the resource goes out of scope is not sufficient - can anyone confirm this?
2. If you use Prepare() method of MySqlCommand class, call Dispose() after closing reader.
Not applicable to our case.
3. If you use connection pooling, call MySqlConnection.Ping() method before MySqlConnection.Open().
Does this mean that, with connection pooling enabled, the MySqlConnection we get from New MySqlConnection() might actually be a MySqlConnection() created on some other thread and which might have other activity outstanding (if, e.g., it had a MySqlDataReader that wasn't closed properly, etc.)? Should I take this to mean that all New'ed MySqlConnection instances should have Ping() called before attempting to Open()? If so, do I need to then Close() the MySqlConnection if the Ping() succeeds, or should I New another MySqlConnection, or both?
4. If above doesn't help and you use connection pooling, check if you can turn connection pooling off.
This is an option but something we'd like to avoid if there is a solution here.
Note: we have a web app with multiple requests in flight at a time, and each request creates multiple worker threads each with its own MySqlConnection instance. I was able to reproduce the "Net packets out of order" error by EXPLICITLY using the same instance of MySqlConnection in multiple background threads simultaneously... which is what leads me to believe that connection pooling is recycling still-active MySqlConnection instances with essentially the same effect.
Any help is appreciated.
pooling=true;server=192.168.1.100;database=dbname;uid=dbuser;pwd=dbpwd;
Sometimes, very infrequently and when the system is under load, we will get errors like "Net packets out of order - expect [X], received [Y]", or similar.
I have done a little reading on the forums and was hoping some of the advice I found could be clarified. Specifically, at the bottom of the first page of this post: viewtopic.php?t=6396
1. Make sure you close all data readers explicitly.
In .NET, we sometimes explicitly call the Close method on the MySqlDataReader and sometimes we just open the MySqlDataReader in a Using block without explicitly invoking the Close method. I am guessing that the Dispose method of MySqlDataReader which Using calls when the resource goes out of scope is not sufficient - can anyone confirm this?
2. If you use Prepare() method of MySqlCommand class, call Dispose() after closing reader.
Not applicable to our case.
3. If you use connection pooling, call MySqlConnection.Ping() method before MySqlConnection.Open().
Does this mean that, with connection pooling enabled, the MySqlConnection we get from New MySqlConnection() might actually be a MySqlConnection() created on some other thread and which might have other activity outstanding (if, e.g., it had a MySqlDataReader that wasn't closed properly, etc.)? Should I take this to mean that all New'ed MySqlConnection instances should have Ping() called before attempting to Open()? If so, do I need to then Close() the MySqlConnection if the Ping() succeeds, or should I New another MySqlConnection, or both?
4. If above doesn't help and you use connection pooling, check if you can turn connection pooling off.
This is an option but something we'd like to avoid if there is a solution here.
Note: we have a web app with multiple requests in flight at a time, and each request creates multiple worker threads each with its own MySqlConnection instance. I was able to reproduce the "Net packets out of order" error by EXPLICITLY using the same instance of MySqlConnection in multiple background threads simultaneously... which is what leads me to believe that connection pooling is recycling still-active MySqlConnection instances with essentially the same effect.
Any help is appreciated.