Bug #25151 Reading from the stream has failed Exception in MySQL Connector 5.0.2
Submitted: 18 Dec 2006 17:20 Modified: 16 Mar 2007 17:05
Reporter: Gauthier dV
Status: Need Doc Info
Category:Connector/Net Severity:S1 (Critical)
Version:5.0.2 beta OS:Microsoft Windows (Windows XP SP2)
Assigned to: Target Version:
Tags: Connection, transport, read, unable, failed, stream, Reading, MySqlClient, MySqlException

[18 Dec 2006 17:20] Gauthier dV
Description:
MySql.Data.MySqlClient.MySqlException: 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.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags
socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.IO.BufferedStream.ReadByte()
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
--- End of inner exception stack trace ---
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
at MySql.Data.MySqlClient.MySqlStream.OpenPacket()
at MySql.Data.MySqlClient.NativeDriver.ReadOk(Boolean read)
at MySql.Data.MySqlClient.NativeDriver.SetDatabase(String dbName)
at MySql.Data.MySqlClient.MySqlConnection.ChangeDatabase(String database)
at MySql.Data.MySqlClient.MySqlConnection.Open()

followed by :

MySql.Data.MySqlClient.MySqlException: Connection unexpectedly terminated.
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
at MySql.Data.MySqlClient.MySqlStream.OpenPacket()
at MySql.Data.MySqlClient.NativeDriver.ReadOk(Boolean read)
at MySql.Data.MySqlClient.NativeDriver.SetDatabase(String dbName)
at MySql.Data.MySqlClient.MySqlConnection.ChangeDatabase(String database)
at MySql.Data.MySqlClient.MySqlConnection.Open() 

How to repeat:
No idea

Suggested fix:
No idea
[19 Dec 2006 18:22] Reggie Burnett
I verified this bug when sending a blob bigger than max block size which is about 16M
[19 Dec 2006 18:25] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/17173
[19 Dec 2006 18:27] Reggie Burnett
Fixed in 5.0.3
[19 Dec 2006 18:32] Gauthier dV
I don't use BLOB in my database...Anything else can cause such bug ?

Thanks in advance

Gauthier dV
[4 Jan 2007 16:07] Reggie Burnett
This error could be caused by several things.  If you continue to get this problem with
5.0.3, you can reopen this bug report or create a new one.  Also, if you could post a
test case that reproduced it or some additional info that would be helpful.

Thanks
[4 Jan 2007 16:25] Gauthier dV
Hi Reggie, 

I found a way to reproduce the bug. The bug arrives when the mysql connector is connected
to a distant database and the mysql service shutdown and restart after.

The firsts errors to come is :
MySql.Data.MySqlClient.MySqlException: 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.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size,
SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.IO.BufferedStream.ReadByte()
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   --- End of inner exception stack trace ---
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.OpenPacket()
   at MySql.Data.MySqlClient.NativeDriver.ReadOk(Boolean read)
   at MySql.Data.MySqlClient.NativeDriver.SetDatabase(String dbName)
   at MySql.Data.MySqlClient.MySqlConnection.ChangeDatabase(String database)
   at MySql.Data.MySqlClient.MySqlConnection.Open()

Followed by somme errors like : 
MySql.Data.MySqlClient.MySqlException: Connection unexpectedly terminated.
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.OpenPacket()
   at MySql.Data.MySqlClient.NativeDriver.ReadOk(Boolean read)
   at MySql.Data.MySqlClient.NativeDriver.SetDatabase(String dbName)
   at MySql.Data.MySqlClient.MySqlConnection.ChangeDatabase(String database)
   at MySql.Data.MySqlClient.MySqlConnection.Open()

And followed by :
System.NullReferenceException: Object reference not set to an instance of an object.
   at MySql.Data.MySqlClient.NativeDriver.Configure(MySqlConnection connection)
   at MySql.Data.MySqlClient.MySqlConnection.Open()

The connector never reconnect to the mysql server....

I must close my service and restart it after.

The first time I had this bug, the mysql server rebooted at 3 am for windows update I
think....

Thank you in advance

gdt
[4 Jan 2007 16:44] Reggie Burnett
Thanks for the update.  I'll check 5.0.3 against your report.
[17 Jan 2007 15:07] David Loomer
FWIW I seem to be having this same problem.  It only seems to happen overnight, although I
know in the case of last night my Win2k server did not reboot for an update but I awoke to
the problem anyway.  It is then likely to be caused by the idle time instead (I have tried
this during the day after a couple hours idle time without error, but maybe it needs 6-8
hours idle time?)  I know of two ways to cure the problem when it occurs: 1) re-start IIS
(my code runs on an ASP .NET website) similar to Gauthier's solution, 2) connect to the
same MySQL instance using MySQL Connector from a different app.

I am using 5.0.3, installed just a couple of days ago.
[17 Jan 2007 15:11] David Loomer
I should add that by "connecting to the MySQL instance using MySQL Connector from a
different app" I mean that this other app is an EXE.  So in other words, this app had not
been running and therefore would not have had any open connections etc, as opposed to my
website which of course is a service.  So something about starting up the app seemed to
wake something up, which my website is unable to do.
[19 Jan 2007 14:49] Dirk Dircksen
Getting this as well.
Have also been able to reproduce this on a consistent basis by doing the following:
1. Console Application spawns 10 threads.
2. Call a simple web service in each thread 10x
3. Web service attempts an insert to MySQL database.
4. Get error.

Reducing the number of threads causes the problem to go away.
[28 Jan 2007 13:47] Dennis Gronewold
Getting this too. Any news on when a fix will be available?
[29 Jan 2007 15:11] bogdan kecman
Getting the error on simple select when more then 5000 rows in result set and compression
turned on. so .. 

string connStr = String.Format("server={0};user id={1}; password={2}; database={3};
pooling=false; port={4}; CharSet=utf8; Connection Timeout=999; compress=true",...);
conn = new MySqlConnection( connStr );
cmd = new MySqlCommand("SELECT * FROM t1", conn);
reader = cmd.ExecuteReader();
while (reader.Read()){...}

this makes "reading from stream has failed" exception after approx 5000 rows. (never
before 1000, allways after 5000, somethimes between 1000 - 5000)

I get this error on 5.0.1, 5.0.2 and also on 5.0.3 

on 5.0.3 when compression is off I do not get the error, but if compression is on i get
error every time after 5000 rows.

any1 with idea ?
[16 Mar 2007 17:05] MC Brown
Setting to NDI while the bug is re-investigated.
[10 May 2007 17:21] Doron E
I'm getting this too.
Is there a fix or a workaround for this problem?

Thanks
[29 May 2007 9:03] Tonci Grgin
Probably related to Bug#27865, Bug#28204 & Bug#28692.
[25 Jun 2007 17:08] pablo viale
I hade the same problem. I was using mysql.data.dll version 5.something.

Believe it or not, I deleted the dll, and placed the 1.0.7.30072 version and the problem
dissapeared.  I tried with this version because I had a couple apps that didn't have this
problem.  So now I am using version 1 on all of them.

I use MySQL Server 5 and ASP.NET 2.0

I will stick to this old 1.0.7.30072 version forever I think, since it has never given me
any problems.
[20 May 2008 18:24] Mike Ehrenberg
I am experiencing the same problem.  It happens just like in David's case.  I only seem to
get this error over-night.  It is a winforms application with about 5 connections on
seperate threads.  I am using version 5.0.8.1
[6 Nov 2008 3:34] Fredrik
Getting this as well. Happens every time the app has been idle for about an hour. Right
after the error is thrown, it works again.

Same problem in two completely different applications - where one of them is using
ADO.net feature, meaning i didn't write a single piece of SQL code myself. So it's
definatively a bug in the driver - not my code.
[6 Nov 2008 3:53] Jared Sullivan
Can anybody match this "Dhcp Error" for the servers EVENTLOG\System?
=====

The description for Event ID 1002 from source Dhcp cannot be found. Either the component
that raises this event is not installed on your local computer or the installation is
corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with
the event.

The following information was included with the event: 

10.1.1.3
0016E663E534
10.1.1.1
[8 Dec 2008 22:35] Jared Sullivan
External doc : "Desktop" Intel motherboards and Full Duplex.
http://www.intel.com/support/network/adapter/pro100/pro100b/sb/cs-015976.htm