Bug #53457 Exceptions during data cleanup in Connection.Dispose()
Submitted: 6 May 2010 7:17 Modified: 28 Jun 2010 14:52
Reporter: Bogdan Degtyariov Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.2.2 OS:Windows
Assigned to: Vladislav Vaintroub CPU Architecture:Any
Tags: Dispose

[6 May 2010 7:17] Bogdan Degtyariov
Description:
GC disposing of MySqlConnection object causes the following exception:

System.IO.EndOfStreamException: Attempted to read past the end of the stream.
MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
MySql.Data.MySqlClient.MySqlStream.LoadPacket()
Outer Exception Reading from the stream has failed.
MySql.Data.MySqlClient.MySqlStream.LoadPacket()
MySql.Data.MySqlClient.MySqlStream.ReadPacket()
MySql.Data.MySqlClient.NativeDriver.FetchDataRow(Int32 statementId, Int32 columns)
MySql.Data.MySqlClient.Driver.FetchDataRow(Int32 statementId, Int32 columns)
MySql.Data.MySqlClient.Driver.SkipDataRow()
MySql.Data.MySqlClient.ResultSet.Close()
MySql.Data.MySqlClient.MySqlDataReader.NextResult()
MySql.Data.MySqlClient.MySqlDataReader.Close()
MySql.Data.MySqlClient.MySqlConnection.Close()
MySql.Data.MySqlClient.MySqlConnection.Dispose(Boolean disposing)
System.ComponentModel.Component.Finalize()

System.NullReferenceException: Object reference not set to an instance of an object.
MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId)
MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId)
MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId)
MySql.Data.MySqlClient.MySqlDataReader.NextResult()
MySql.Data.MySqlClient.MySqlDataReader.Close()
MySql.Data.MySqlClient.MySqlConnection.Close()
MySql.Data.MySqlClient.MySqlConnection.Dispose(Boolean disposing)
System.ComponentModel.Component.Finalize()

How to repeat:
No need to repeat, the fix is intuitive when looking at the stack trace.

Suggested fix:
We should eat the exception somewhere in ResultSet.Close() or Driver.SkipDataRow()
[6 May 2010 11:23] Tonci Grgin
Note, Bug#53439
[6 May 2010 11:31] Pavel Bazanov
I don't think that eating exceptions is a solution.
Exceptions must be eaten only in very rare, exclusive cases. Otherwise eating exceptions just hides bugs in code.
[10 Jun 2010 19: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/110764
[10 Jun 2010 19:31] Vladislav Vaintroub
pushed to 6.2 and later
[24 Jun 2010 10:15] Vladislav Vaintroub
fixed in 6.0.7, 6.1.5, 6.2.4, and 6.3.3+
[28 Jun 2010 14:52] Tony Bedford
An entry has been added to the 6.0.7, 6.1.5, 6.2.4, 6.3.3 changelogs:

Garbage Collector disposal of a MySqlConnection object caused the following exception:

System.IO.EndOfStreamException: Attempted to read past the end of the stream.
MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset,
Int32 count)
MySql.Data.MySqlClient.MySqlStream.LoadPacket()
Outer Exception Reading from the stream has failed.
...