MYSQL connector 的 NullReferenceException bug

darren__chan發表於2020-09-14

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 Dispose

The 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 value

Bug#91106

Suggested 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.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29863023/viewspace-2719547/,如需轉載,請註明出處,否則將追究法律責任。

相關文章