MYSQL connector 的 NullReferenceException bug

来源:这里教程网 时间:2026-03-01 15:22:49 作者:

mysql connector 连接报错,  客户端在 MySqlClient.MySqlDataReader.NextResult() 处报错 ,IIS 进程池 crash db 端提示 Got an error reading communication packets 异常时堆栈调用信息:ServerConnectionInfo.Finallize()=>ServerConnectionInfo.Dispose()=>MySqlConnection.Dispose()=>MySqlConnection.Close()=>MySqlDataReader.Close()=》MySqlDataReader.NextResult()     从堆栈调用信息来看,是从程序中发起了Dispose(),后再调用了MySqlConnection.Dispose()进行关闭。         在这里MySqlConnection.Close()又调用MySqlDataReader.Close()=》MySqlDataReader.NextResult(),从应用代码了解到MySqlConnection.Close()一般应为正常关闭的最后一步,而MySqlDataReader.Close()应在MySqlConnection.Close()之厚,这看起来是个非正常行为。         报错信息与connector 的 Bug#91106 NullReferenceException in Finalize crashes applications及Bug#90845 NullReferenceException on connection close比较匹配,易工已通过修改connetor源码进行测试。Bug#90845: Description:A NullReferenceException is thrown on MySqlConnection DisposeThe NullReference came from the setter of the property Reader.In the getter the driver has a null check but in the setter it is treated as a NotNull valueBug#91106Suggested fix:       The MySqlDataReader that is used underneath by the command and dataadapter should have been disposed of when the commmand and dataadapter were disposed. I think that is probably a bug.       If it wasn't disposed of correctly then, the finalize method should not assume the driver and driver.stream are not null. or you can catch these exceptions in dispose and not crash the program.

相关推荐