Bug #76597 Reading from stream failed
Submitted: 5 Apr 2015 18:31 Modified: 15 May 2015 13:39
Reporter: Shyamal Parikh Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Errors Severity:S1 (Critical)
Version:5.6.20 OS:Windows (Win 7)
Assigned to: CPU Architecture:Any
Tags: mysql_native_password, Stream failed

[5 Apr 2015 18:31] Shyamal Parikh
Description:
I am facing the following error intermittently. It is solved by using 'skip name resolve' option in the mysql server settings. 

However, as per many suggestions found on net, using 127.0.0.1 should have solved the issue. But this too didn't help can you suggest me a workaround or a SQL command through which I can check the 'skip name resolve' option.

Error 1: 0
    Authentication to host '127.0.0.1' for user 'root' using method 'mysql_native_password' failed with message: Reading from the stream has failed.

How to repeat:
Try 7 connections per second using '127.0.0.1'. I am not sure this would definitely cause an error as it happens randomly.
[6 Apr 2015 6:43] Chiranjeevi Battula
Hello Shyamal Parikh,

Thank you for the bug report.
Provided information could not be sufficient to confirm the bug.
Could you please provide complete technology information and repeatable test case to confirm this issue at our end?

Thanks,
Chiranjeevi.
[6 Apr 2015 9:35] Shyamal Parikh
I have a C# app which establishes connection with MySQL. It also has background threads which run MySQL queries. 

As per client connections tab in the MySQL Workbench it can be interpreted that there are constant 5 connection threads connected due to the C# app.

Now I don't know why skip-name-resolve solves the issue even when I am using 127.0.0.1 in the connection string => datasource = 127.0.0.1; port =3306; username = root; password = root 

Note: Error occurs intermittently there is no way I can predict or guess when it's going to happen again.
[6 Apr 2015 11:02] Chiranjeevi Battula
Hello Shyamal Parikh,

Thank you for your feedback.
This is a look likes duplicate of Bug #72110, please see the explaination by dev's in #72110.

Quoting from #72110 - [21 May 15:40] Francisco Alberto Tirado Zavala:

When you are working with a Client-Server application all the connections are performed by Sockets, when you create a connection you open a Socket between your client and your server, and an 

Id/ProccesId is assigned/reserved in the server for the connection requested by the client. Also you must consider that the server can terminate or close a connection if the connection is inactive 

after some time, so you need to create a new valid connection opening a new socket to get a valid Id from the server.

If you can't change the design in your application (having a global connection), as a workaround you can have a method to validate that the connection is valid, for example the following method 

ping the server and if the ping fails it open the connection again:

. . .
MySqlConnection _conn = new MySqlConnection("MyConnectionString");
private void CheckConnection()
{
   if(!_conn.Ping())
   {
     _conn.Open();
   }
}
. . .

As you can see the code is very simple and it works in the following way: when the connection try to ping the server if the connection is invalid, internally the stream that has the socket 

information will be terminated and the connection will be set on status closed as well as the invalid connection will be removed, then opening the connection again will create a new connection 

which means a new valid socket. If the ping succeed so you will continue using the same connection.

To use it you can call it before trying to perform an action to the database, and the connection will be re-opened just when is invalid:

. . .
private void button1_Click(object sender, EventArgs e)
{
  //assuming that the connection is already open
  CheckConnectionState();
  var cmd = new MySqlCommand("select 1", _conn);
  cmd.ExecuteNonQuery();
}
. . .

This is just a workaround, and as far I know all the connections to any database server will have the same behavior.

Same bug was reported in MySQL forums
http://forums.mysql.com/read.php?38,579848,579956#msg-579956

Thanks,
Chiranjeevi.
[9 Apr 2015 6:19] Shyamal Parikh
I don't think the solution suggested is going to work. Let me explain why.

1. The error I am getting is to do with authentication to host '127.0.0.1' that is I am trying to connect to local MySQL Server and MySQL is failing to authenticate the IP(This is solved when I select the -skip-name-resolve option.)

2. I also have other computers in LAN which has the same C# app running(ofcourse with the server IP for eg: 192.168.0.8) and they don't get this error. So the problem is limited to Application running on PC having MySQL server only. Again it points towards name resolve issue.

I think MySQL is not able to resolve host name of 127.0.0.1 IP. Now MySQL server 5.6 documentation says that for IP 127.0.0.1 host name is not checked so this is a discrepancy. May be I am overlooking something or MySQL do try to get hostname for 127.0.0.1 and fails to retrieve it giving out an authentication error.
[14 Apr 2015 6:12] Shyamal Parikh
Guys what is the latest on status on this bug? It has been a long time and I really need a solution to this.

If you can even provide with a MySQL Command which I can run to check 'skip-name-resolve' it would be great.
[23 Apr 2015 6:58] Chiranjeevi Battula
Hello Shyamal Parikh,

Thank you for your feedback.
The error is due to server closing the socket due to timeout, so the client side can do little here, but you can certainly try:

a) Increase the net_write_timeout & net_read_timeout (like 999999).
b) Read the data in small chunks, like
select * from table1 limit 1,100000
select * from table1 limit 100000,199999
select * from table1 limit 199999,299999 
and so on.
Please check if the workaround suggested by dev's(pls see #57365 - [11 Oct 2012 3:27] Fernando Gonzalez Sanchez) works.
Feel free to open the bug if the workaround doesn't work(include details of log file, and steps to reproduce the issue at our end).

Thanks,
Chiranjeevi.
[23 Apr 2015 13:49] Shyamal Parikh
I repeat again the error I face is when my "local" app tries opening a "localhost"(127.0.0.1) connection. This essentially means there is no client in the picture!!

And I ask again can you please tell me how I can activate "-skip-name-resolve" programmatically through a SQL query?
[23 Apr 2015 16:27] MySQL Verification Team
See bug: http://bugs.mysql.com/bug.php?id=75917 probably a duplicate and see
https://bugs.mysql.com/bug.php?id=72110 also about comment [21 May 2014 15:40] Francisco Alberto Tirado Zavala. Thanks.
[12 May 2015 17:03] Shyamal Parikh
Ok so I read the bugs @Miguel Solorzano pointed to. Now please try to understand I am opening a new connection every time I want a query to be executed. I am attaching an example here:

string myconnection = "datasource = localhost;port=3306;username=root;password=*****;
            MySqlConnection myConn = new MySqlConnection(myconnection);     //Connect to MySql
            string Query = " SELECT * FROM db1.table1;";
            MySqlCommand cmdDatabase = new MySqlCommand(Query, myConn);     //Command for the database

            MySqlDataReader myReader;
            try
            {
                myConn.Open();
                myReader = cmdDatabase.ExecuteReader();

                while (myReader.Read())
                {
                    //Do something
                }
            }
            catch (MySqlException ex)
            {
                //Do Something
            }
            catch (SocketException ex)
            {
                //Do Something
            }
            catch (Exception ex)
            {
                //Do Something
            }
            myConn.Close();

As seen above I am opening a new connection every time I want a query to be executed. Moreover, please consider this - even if I am trying to execute a query with localhost ie 127.0.0.1 IP I am facing the same error :

Authentication to host '127.0.0.1' for user 'root' using method 'mysql_native_password' failed with message: Reading from the stream has failed.

NOTE: Recently when I started the server system (my app autoruns at startup) I got the same error as above. That means there were no existing connections and hence there were no 'invalid connections' that my C# app was trying to access. 

I hope I have made the issue crystal clear now and I hope you would help me solve this issue.
[12 May 2015 17:04] Shyamal Parikh
The Error I am facing

Attachment: Error example.jpg (image/jpeg, text), 298.96 KiB.

[13 May 2015 7:50] Chiranjeevi Battula
Hello Shyamal Parikh,

Thank you for your feedback.
I tried to reproduce the steps at my end, but couldn't trace out any issue with database connection and could you please verify the user permissions.

Thanks,
Chiranjeevi.
[13 May 2015 7:51] Chiranjeevi Battula
screenshot

Attachment: 76597.PNG (image/png, text), 73.81 KiB.

[13 May 2015 14:51] Shyamal Parikh
Ya, the localhost connection has full rights. The error occurs intermittently so may be you would need to run the application for long to have one.
[15 May 2015 13:39] Chiranjeevi Battula
Hello Shyamal Parikh,

Thank you for your feedback.
I could not repeat this issue at my end with the provided information. 
If you can provide more information, feel free to add it to this bug and change the status back to 'Open'.

Thank you for your interest in MySQL.

Thanks,
Chiranjeevi.
[1 Jun 2015 9:49] Chiranjeevi Battula
http://bugs.mysql.com/bug.php?id=77203 marked as duplicate of this one.
[3 Jul 2015 13:56] Mohd Sahar
Hi,
Below my stack trace

Stack Trace: 

[SocketException (0x2745): An established connection was aborted by the software in your host machine]
   System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +249

[IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.]
   MySql.Data.Common.MyNetworkStream.HandleOrRethrowException(Exception e) +261
   MySql.Data.Common.MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count) +424
   MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count) +220
   System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count) +185
   MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count) +132
   MySql.Data.MySqlClient.MySqlStream.LoadPacket() +142

[MySqlException (0x80004005): Reading from the stream has failed.]
   MySql.Data.MySqlClient.MySqlStream.LoadPacket() +811
   MySql.Data.MySqlClient.MySqlStream.ReadPacket() +88
   MySql.Data.MySqlClient.NativeDriver.ReadPacket() +81
   MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket() +93

[MySqlException (0x80004005): Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Reading from the stream has failed.]
   MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex) +450
   MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket() +180
   MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset) +673
   MySql.Data.MySqlClient.NativeDriver.Authenticate(String authMethod, Boolean reset) +278
   MySql.Data.MySqlClient.NativeDriver.Open() +2794
   MySql.Data.MySqlClient.Driver.Open() +126
   MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) +407
   MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() +53
   MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() +453
   MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() +265
   MySql.Data.MySqlClient.MySqlPool.GetConnection() +166
   MySql.Data.MySqlClient.MySqlConnection.Open() +2600
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +292
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +420
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +275
   AMS._default.Page_Load(Object sender, EventArgs e) in D:\Users\mrart\Dropbox\My Projects\OWN\AMS Solutions\AMS\default.aspx.cs:35
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178
[13 Jul 2015 6:09] Chiranjeevi Battula
http://bugs.mysql.com/bug.php?id=77691 marked as duplicate of this one.
[18 Aug 2015 9:50] Marcel Müller
I can confirm that this error randomly pops up in all our .net applications connecting to MySQL 5.6.24. This occured directly after updating from MySQL 5.0.x to 5.6.24 (never got this exception with 5.0.x). The workround (pinging the DB first and then open a new connection if it fails) is already implemented in our wrapper classes. Something like this:

---
    Private _db As MySqlConnection

    Public ReadOnly Property Connected() As Boolean
        Get
            Return Not _db.State = ConnectionState.Closed AndAlso _db.Ping
        End Get
    End Property

    Public Sub Open(ByVal ConnectionString As String)
        If _db Is Nothing OrElse Not Connected Then
            _db = New MySqlConnection
            _db.ConnectionString = ConnectionString

            _db.Open()
        End If
    End Sub
---

I'm wondering if 5.6 (in contrast to 5.0) may close the connection while authentication is ongoing?! I tried to create a reproducable example, but I'm unable to do so. This just randomly pops up without any pattern...

Exception:
MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host '...' for user 'root' using method 'mysql_native_password' failed with message: Reading from the stream has failed. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
   at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Authenticate(String authMethod, Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
[19 Aug 2015 23:32] scott mankowitz
I don't have a solution to this problem, but I did find a workaround.

My use case was that I was running the program as a scheduled task in windows server 2008. When I ran the program from within visual studio, it worked fine. 

Pinging the connection to see if it was open did no good. 

However, I found that if I explicitly close the connection before ending the program, it worked well. 

hope this helps.
[22 Aug 2015 18:05] Marcel Müller
Thanks scott for your help! Sadly I'm already closing each connection after its been used. Although I'm using pooling, so a "db.close()" does not close the underlaying connection to the server... 

Looking at the stacktrace and the .net connector source again "GetPooledConnection()" already does a "Ping()" if it gets a driver from the pool. 

I also noticed that I nearly always create a new MySqlConnection-object rather than using an already existing one, so my code containing"Ping()" does really nothing, as this object never connected to the server before.
[15 Sep 2015 10:15] Abraham Guyt
Having the same problem on Windows 2008 x64 SP2 with MySql 5.6.19.

Exception is triggered when the client tries to connect to the server for the 1st time.

Normally logging into the server manually with the mysql command-line client works normally.

Any solution?
[17 Sep 2015 16:52] Carl Bartlett
I have a similar problem I am running a window application on a EC2 instance. The application makes a large number of connections over time to a mysql DB running on RDS.  This normally works fine however on rare occasions I have a exception that says I cant read from the stream.  At this point the application and EC2 instance becomes almost unresponsive.  The only way is to fix it is to shutdown the application.  (THIS is not an acceptable solution in this case)

I have included the call stack for the exception

Authentication to host '*********.ccaugtcoz2r0.us-west-2.rds.amazonaws.com' for user '*******' using method 'mysql_nat
ive_password' failed with message: Reading from the stream has failed.
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Authenticate(String authMethod, Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at ServerCommon.Lib.PersistentData.SqlConnect..ctor(String database) in {my code}
[1 Oct 2015 5:30] Chiranjeevi Battula
http://bugs.mysql.com/bug.php?id=78650 marked as duplicate of this one.
[2 Oct 2015 15:45] Thomas Johnson
This bug ends stating its a duplicate of 78650, but 78650 ends stating it's a duplicate of this bug.  you have circular reference I'm thinking it may not be looked at.  

This issue just occurred for me too.  I have a .net website which has pooling enabled that failed on opening the connection.

Error Message : 
Authentication to host 'AAA.BBB.CCC.com' for user 'UUU' using method 'mysql_native_password' failed with message: Reading from the stream has failed. 

Stack Trace : 	
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at MySQLDB.StartTransaction(String connectionString)
at PARCELite.ActiveReportsLog.StartLog(Page currentPage, ActiveReport myReport, ParameterList myValues)
at PARCELite.ReportView.Page_Init(Object sender, EventArgs e)
at System.Web.UI.Page.OnInit(EventArgs e)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 

We upgraded from 5.0 to 5.1 to 5.5 and finally to 5.6.26 a month ago and this is the first we seen this.

Using: MySQL Connector NET 6.9.7

connectionString="database=DDD; server=AAA.BBB.CCC.com; uid=UUU; pwd=PPP; pooling=true"
[7 Dec 2015 23:22] Eric Couch
This started happening to our app when we upgraded to 5.6.26
   It only happens 10% of the time randomly. I ping before I open and I close every connection.
   
   MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host 'localhost' for user 'xxx' using method 'mysql_native_password' failed with message: Reading from the stream has failed. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed. ---> System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at MySql.Data.Common.MyNetworkStream.HandleOrRethrowException(Exception e)
   at MySql.Data.Common.MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at SecureDockDataAccess.DBAccess.Execute(String sql)
[7 Dec 2015 23:26] Carl Bartlett
What did you update from?
[20 Jan 2016 5:31] Bibhuti Narayan
By Default pooling is true in the connection string, we have tried setting it as false and then we did not get this error. 

But the CPU utilization is going high for
- mysqld.exe
- WmiPrvSE.exe
[7 Jul 2016 6:04] Chiranjeevi Battula
http://bugs.mysql.com/bug.php?id=82136 marked as duplicate of this one.
[7 Jul 2016 6:32] yx jiang
Ping does not work.

I believe this is a problem in low level.
[19 Sep 2016 6:54] Tushar Agarwal
It didn't happen to my app until I was using 5.5.
Recently I migrated to 5.7 and this started appearing.

Nothing at code level/libraries has changed. Looks like an issue with the server.

Did skip-domain-resolution work for anyone?
[26 Sep 2016 8:46] Marcel Müller
I'm still seeing this problem here and there. Happend today while in a debug session, here's the stacktrace including all inner exceptions:

Authentication to host 'mysql...local' for user 'root' using method 'mysql_native_password' failed with message: Reading from the stream has failed.
   bei MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
   bei MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   bei MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
   bei MySql.Data.MySqlClient.NativeDriver.Authenticate(String authMethod, Boolean reset)
   bei MySql.Data.MySqlClient.NativeDriver.Open()
   bei MySql.Data.MySqlClient.Driver.Open()
   bei MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   bei MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   bei MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   bei MySql.Data.MySqlClient.MySqlPool.GetConnection()
   bei MySql.Data.MySqlClient.MySqlConnection.Open()
   bei Dapper.SqlMapper.<MultiMapImpl>d__140`8.MoveNext()
   bei System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   bei System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   bei Dapper.SqlMapper.MultiMap[TFirst,TSecond,TThird,TFourth,TFifth,TSixth,TSeventh,TReturn](IDbConnection cnn, String sql, Delegate map, Object param, IDbTransaction transaction, Boolean buffered, String splitOn, Nullable`1 commandTimeout, Nullable`1 commandType)
   bei Dapper.SqlMapper.Query[TFirst,TSecond,TThird,TReturn](IDbConnection cnn, String sql, Func`4 map, Object param, IDbTransaction transaction, Boolean buffered, String splitOn, Nullable`1 commandTimeout, Nullable`1 commandType)
   bei [...]

Inner:
Reading from the stream has failed.
   bei MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   bei MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   bei MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()

Inner:
Von der Übertragungsverbindung können keine Daten gelesen werden: Eine bestehende Verbindung wurde softwaregesteuert
durch den Hostcomputer abgebrochen.
   bei MySql.Data.Common.MyNetworkStream.HandleOrRethrowException(Exception e)
   bei MySql.Data.Common.MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   bei MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   bei System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)
   bei MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
   bei MySql.Data.MySqlClient.MySqlStream.LoadPacket()

Inner:
Eine bestehende Verbindung wurde softwaregesteuert
durch den Hostcomputer abgebrochen
ConnectionAborted {10053}
   bei System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   bei System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

I think by "skip-domain-resolution" you mean "skip-name-resolve"?! This is enabled in my setup, but I still get this error. Very annoying.
[26 Dec 2016 2:20] Liu Alan
I simulated such anomalies in the local environment

Attachment: QQ图片20161226101918.png (image/png, text), 130.59 KiB.

[12 Jan 2017 19:41] Guy Jackman
I know this bug is old, but it is still unresolved.  Unfortunately, I can't add a lot of additional information since I don't know how to synthetically recreate it.

I have a C# application that uses Entity Framework and the MySQL connector to cycle through about 25 different database servers and perform some basic work.  One of the 25, which otherwise has no problems, consistently throws the error that others have described.
Other details:
- I've NEVER seen this problem when executing the same application directly through Visual Studio
- The error is consistently thrown when run in a Windows scheduled task context that runs once per day.  Between executions I have verified that the application process has stopped, and there are no network connections to the MySQL server (checked using SysInternals TCPView).
- It occurs consistently (after the first successful execution) for only one of many servers
- It does NOT occur the first time that I execute the code AFTER a restart of the server MySQL instance.
- Client: MySQL.Data 6.9.9, MySQL.Data.Entity.EF6 6.9.9
- Server MySQL:  5.5.5
- Client Execution Context:  C# Command Line App, Framework 4.0, running once per day as a scheduled task
- I have compared copies of all the server variables between MySQL servers and find no differences.
Error:
2017-01-11 06:03:40,654 [1] ERROR XXX.L2K.SAPBOMComparer.Program - The underlying provider failed on Open.
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> MySql.Data.MySqlClient.MySqlException: Authentication to host 'line58.mesaii.XXX.com' for user 'l2kread' using method 'mysql_native_password' failed with message: Reading from the stream has failed. ---> MySql.Data.MySqlClient.MySqlException: Reading from the stream has failed. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
   at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   --- End of inner exception stack trace ---
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   --- End of inner exception stack trace ---
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   --- End of inner exception stack trace ---
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass3.<GetResults>b__1()
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Linq.Queryable.Single[TSource](IQueryable`1 source)
   at XXX.L2K.SAPBOMComparer.Program.ProcessLinehost(List`1& comparisons, PLRInterfaceEntities dbPLR, Line thisLine, List`1 hostPartList) in C:\Users\XXXXXX\Documents\Visual Studio Projects\XXX.L2K.SAPBOMComparer\Program.cs:line 94
   at XXX.L2K.SAPBOMComparer.Program.Main(String[] args) in C:\Users\XXXXXX\Documents\Visual Studio Projects\XXX.L2K.SAPBOMComparer\Program.cs:line 58

I recently (yesterday) modified the code to set the connection string to turn off connection pooling.  Today, for the first time in weeks, the error did not occur.  I will followup with an additional comment if this changes.
[12 Jan 2017 19:46] Guy Jackman
In my comment above, it may be important to note that the connection strings are IDENTICAL between all connections and servers, with the obvious exception of the server names and database names.
[13 Jan 2017 16:03] Guy Jackman
Ok, not related to connection pooling.  First connection after disabling pooling succeeded, but failed the next morning.  Ultimate error is the same, but the non-pooled version of the error is here:
2017-01-13 06:06:07,260 [1] ERROR XXX.L2K.SAPBOMComparer.Program - The underlying provider failed on Open.
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> MySql.Data.MySqlClient.MySqlException: Authentication to host 'line58.mesaii.XXX.com' for user 'l2kread' using method 'mysql_native_password' failed with message: Reading from the stream has failed. ---> MySql.Data.MySqlClient.MySqlException: Reading from the stream has failed. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
   at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   --- End of inner exception stack trace ---
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   --- End of inner exception stack trace ---
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   --- End of inner exception stack trace ---
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass3.<GetResults>b__1()
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Linq.Queryable.Single[TSource](IQueryable`1 source)
   at XXX.L2K.SAPBOMComparer.Program.ProcessLinehost(List`1& comparisons, PLRInterfaceEntities dbPLR, Line thisLine, List`1 hostPartList) in C:\Users\XXXXXX\Documents\Visual Studio Projects\XXX.L2K.SAPBOMComparer\Program.cs:line 94
   at XXX.L2K.SAPBOMComparer.Program.Main(String[] args) in C:\Users\XXXXXX\Documents\Visual Studio Projects\XXX.L2K.SAPBOMComparer\Program.cs:line 58
[23 Jan 2017 10:15] Tom Chiang
mysql client

Attachment: mysql.png (image/png, text), 159.96 KiB.

[23 Jan 2017 10:16] Tom Chiang
mysql client

Attachment: mysql.png (image/png, text), 159.96 KiB.

[23 Jan 2017 10:19] Tom Chiang
Same here,
I am using Windows Server 2012, MySQL 5.7.17, .Net Connector 6.9.9

My server runs as Application Server (which will execute many SQL insert statement as schedule tasks, with multi-thread console programs), Web Server and Database Server.
Exception Message: Authentication to host 'localhost' for user 'username' using method 'mysql_native_password' failed with message: Reading from the stream has failed.

The error is unpredictable, when the above exception thrown, my server includes IIS will response super slow, and then finally return the above error message through web browser.

One more interesting thing is, when the error occurs, my connections drops a lot, and alos the incoming network traffic, outgoing network traffic, SQL statements Executed(#) etc... and the "InnoDB Disk Writes" will raise. (Please find the attached photo)
[23 Jan 2017 10:28] Tom Chiang
It affects my Web Server also... It throws "Error" in my event log repeat and repeat..

Attachment: IIS.png (image/png, text), 163.83 KiB.

[23 Jan 2017 15:05] Tom Chiang
MySQLErrorScreenCap

Attachment: MySQLErrorScreenCap.png (image/png, text), 752.62 KiB.

[23 Jan 2017 15:06] Tom Chiang
Attached a detailed screen capture [MySQLErrorScreenCap.png] that "Reading from stream failed" occurs. 
You can see there are some patten when "Reading from stream failed" error comes. (1) My C# console program CPU usage will drop to zero (maybe waiting MySQL connection timeout). 
(2) All MySQL client connections from my console programs call will be dropped, only remains the MySQL workbrench client connections. 
(3) MySQL will write I/O on my disk (Although I have assigned 9G innodb_buffer_pool_size) 
(4) The connection string didn't change when programs running, the db user has the rights to insert/update/select/delete. 
(5) I cannot predict when the error occur. 

P.S. My server specifications: Xeon E5-2620 v3 with 4 Cores, 12GB Ram, with SSD Disk. 

Do I need to rollback the MySQL version before 5.5? or are there some problems/bugs with .NET connector 6.9.9? 
Please advise, million thanks!
[23 Jan 2017 20:21] Guy Jackman
For anyone having this problem specifically when running in the context of a Windows Scheduled Task, I've finally found a fix that is working for me.

It turns out that scheduled tasks are launched, by default, at a very low process priority relative to the priority that a task gets when launched interactively.  I noticed that my particular application, launched as a scheduled task, executed an order of magnitude more slowly.

I can't explain why this would cause a specific MySQL client issue, but perhaps there is a timing critical section of the connection code that causes the problem.  I was having the problem, more or less consistently, for weeks.  Since the change in priority, I've had no problems for 3 days straight.

If you want to try this solution, here are the steps:
1.Create the task
2.Right click on the task and "export" it
3.Edit the task.xml file that you just exported
4.You will find a line similar to <Priority>7</Priority>
5.Change the value to a normal priority (between 4-6, I used 5)
6.In the task scheduler, delete the task you initially created
7.In the task scheduler, in the actions area, import the task from the XML file

I found this information here:  http://serverfault.com/a/257183
[24 Jan 2017 2:35] Tom Chiang
Thanks Guy Jackman to share you solution.
I have tried to export the schedule tasks into XML, and edited the Priority into 5, deleted the existing schedule tasks and import again.

When it auto runs the schedule tasks, the errors still come. Seems not work to me...
Does anyone can share another ways to fix this issue? Thanks so much!!
[5 Mar 2017 7:58] Rui Fan
I see the same issue on one (and only) of my Windows Server 2016. My app is an NT service which is using .NET connector 6.9.9 and MySQL 5.7.17(on another CentOS). The first connection on this machine will always fail with the following exception:
MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host '172.16.0.182' for user '********' using method 'mysql_native_password' failed with message: Reading from the stream has failed. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed. 

But the subsequent calls succeeded as long as there're active connections from the same machine. If all the connections are closed due to idle timeout, the same exception will appear again.

The exception always has a 15 seconds delay after the first connection attempt. So it looks like a socket timeout issue. During this 15 seconds, one connection from the same machine with username=None can be found in the MySQL Workbench. And the connection disappeared as soon as the exception was thrown.

By setting the minimum pool size=5 the exception will only appear once unless I restart my NT service. This helps to keep connections alive even if my service is idle. But doesn't help to eliminate the exception.
[23 Mar 2017 15:17] Llyr Jones
As above, this bug affect things such as MVC applications and .WCF applications.

It works fine when debugging and developing in visual Studio 2015, however when running in IIS it crashes a lot with;

MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host 'host' for user 'user' using method 'mysql_native_password' failed with message: Reading from the stream has failed. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
   at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationFailed(Exception ex)
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.ReadPacket()
   at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at 'my own method'

This needs sorting. I'm having to query the database with a ping surrounded by try catch in order to get the connection going.

Once the connection has failed once, it works perfectly fine afterwards until the connection closes.

This bug needs sorting!
[3 Apr 2017 20:19] toni neumann
It looks like the bug is in the data adapter for mysql and .Net.  I went back to MySql.Data.dll v6.4.4.0.  With this version of the client adapter, I am able to open connections and perform hundreds of database operations on the connection without this error.

As soon as I update to the latest published connector in Nuget, I start getting the error frequently.
[24 Apr 2017 14:13] Natan Vivo
I'm having tons (tens of thousands/hour) of this error on multiple servers. After some investigation, I also believe this bug is time related. When the server is under heavy load or any other reason that can cause the process to be slower than normal (cloud environments are very susceptible to this due to multi-tenancy), and this error will popup, and very frequently.

It seems to me the issue in MySqlStream:

    internal static void ReadFully(Stream stream, byte[] buffer, int offset, int count)
    {
      int numRead = 0;
      int numToRead = count;
      while (numToRead > 0)
      {
        int read = stream.Read(buffer, offset + numRead, numToRead);
        if (read == 0)
        {
          throw new EndOfStreamException();
        }
        numRead += read;
        numToRead -= read;
      }
    }

ReadFully takes a naive approach on what it means to read the stream to the end. If the buffer is not filled when the read happens, it assumes it reached the end of the stream, while the server is simply slower to respond.

It would be better to read until the procotol has all the data or a timeout has been reached.

In order to reporduce this, you need to introduce latency in filling the buffers.
[24 Apr 2017 14:34] Natan Vivo
Created a new bug to call attention from the team, as this is closed.

https://bugs.mysql.com/bug.php?id=86056
[27 Oct 2017 10:27] Rui Fan
I've identified the root cause of one case of this exception. If you always see this exception at the first connection to the database, my solutions may apply to you. 
The 3 possible solutions:
Solution 1: If SSL is not required. Since it is caused by SSL, we can turn off SSL by appending "SslMode=None" to the connection string.
Solution 2: If SSL is required, server identity is important and needs to be verified. Connect the server to the internet and try again. 
Solution 3: If SSL is required but the server identity is not important. Typically SSL is only used to encrypt the network transport in this case. We can turn off CTL update:
1. Press Win+R to open the "Run" dialog 
2. Type "gpedit.msc" (without quotes) and press Enter
3. In the "Local Group Policy Editor", expand "Computer Configuration", expand "Administrative Templates", expand "System", expand "Internet Communication Management", and then click "Internet Communication settings".
4. In the details panel, double-click "Turn off Automatic Root Certificates Update", clickEnabled, then click OK. This change will be effective immediatelly without restart.

More details can be found in my blog:
http://blog.csdn.net/fancyf/article/details/78295964
[29 Nov 2017 10:14] Chiranjeevi Battula
http://bugs.mysql.com/bug.php?id=88687 marked as duplicate of this one.
[11 Jan 2018 11:28] Chiranjeevi Battula
http://bugs.mysql.com/bug.php?id=89165 marked as duplicate of this one.
[5 Feb 2019 10:36] MySQL Verification Team
Bug #94190 marked as duplicate of this one
[18 Feb 2019 6:18] Hardik Shah
Hello All,

We have recently found this error increasing in our ASP.NET MVC Application. We are connecting to MySQL using MySQL DLL (6.8.3.0) and our MySQL version is 5.6.19-log. Just to update you all, we have different application and database server connecting through Internet.

We have tried all the options suggested in this bug report.

1. Restarted the Application Server
          - This resolved error for 2-3 days, but again after that it started appearing as around 100 per day.

2. SSL changes
          - Done both Connection String change in Web.Config and Group Policy change. But issues remains same.

3. skip-name-resolve
          - Again no difference.

4. read_net_timeout and write_net_timeout
          - changing value of this variables - no difference

Please suggest us as this has started becoming a random issue which is not resolvable. Also, this error appears only for few seconds, but at that time the MySQL connections are in like below.

unauthenticated user  - <IP> - <DB> - Connect - NULL - Reading from net - NULL
unauthenticated user  - <IP> - <DB> - Connect - NULL - Reading from net - NULL
unauthenticated user  - <IP> - <DB> - Connect - NULL - Reading from net - NULL
unauthenticated user  - <IP> - <DB> - Connect - NULL - Reading from net - NULL
unauthenticated user  - <IP> - <DB> - Connect - NULL - Reading from net - NULL
unauthenticated user  - <IP> - <DB> - Connect - NULL - Reading from net - NULL

Once it releases the connection, we get below error messages.
Authentication to host <IP> for user <USER> using method 'mysql_native_password' failed with message: Reading from the stream has failed.

Please suggest us some solution here which is a permanent solution.

Thanks
Hardik
[22 Apr 2019 13:35] Michael Wheat
This bug just cropped up again.  I was using MySql.Data, Version=8.0.14.0 with no problems, when I upgraded to MySql.Data, Version=8.0.15.0 it happens on the first log in to the application. Hitting the refresh on the page loads up everything correctly.  This isn't happening in my local environment (Windows 7), only on my server (Windows Server 2012).  It happens on the server even when I am using the server locally (log in directly to server and running the app on the server).

After refresh everything seems to work smoothly.  If I shut down the web app and reopen the page it has no issues either, unless I wait about 2 minutes between shutting down the browser and trying again, then I get the error again.
[22 Apr 2019 13:49] Michael Wheat
I had changed my connection timeout from 10 to 600 last week, and it seemed to work for awhile, but it had issues again this morning.  I just double checked the connection timeout...over the weekend apparently it reverted back to 10.
[22 Apr 2019 13:50] Michael Wheat
I had changed my connection timeout from 10 to 600 last week, and it seemed to work for awhile, but it had issues again this morning.  I just double checked the connection timeout...over the weekend apparently it reverted back to 10.
[15 Aug 2019 13:20] Bharathirajan D
Solution provided here.. https://blog.csdn.net/fancyf/article/details/78295964
[23 Jun 2021 11:16] YAKUP ULUTAŞ
this problem still persists , details explained here

mysql version 5.6.28 , connector versions 8.0.23

https://stackoverflow.com/questions/68085943/mysql-reading-from-the-stream-has-failed
[28 Jan 2022 13:48] Bo Henriksen
I have just experienced the same issue.
It happened when I updated my settings on a client running C#.
I simply changed the connection string from using the ip of the server (172.30.16.132) to using a dns name (production-sql).
When this changed the error came up in around 5 percent of the requests.

I changed the connection string back to ip, and the problem disappeared.

It might be an error on our network in respect to the dns settings, but this is still to be investigated. Bottom line is that the problem happens for us when we're using dns names, and not if we are using the ip of the server.

We have other applications running on other machines using the same database, which did not have the problem (they are all using the ip of the database in the connection string).

I hope this information can help someone.