Bug #118579 Stack Overflow Exception When Connecitons Aborted During Connect
Submitted: 2 Jul 16:35 Modified: 7 Jul 11:47
Reporter: Adam Conway Email Updates:
Status: Need Feedback Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:8.1.0 OS:Linux (Oracle Linux 9)
Assigned to: MySQL Verification Team CPU Architecture:x86

[2 Jul 16:35] Adam Conway
Description:
We use the connector for a dotnet service which we have recently migrated from .Net Framework (running therefore on Windows) to .Net 8 and running on Linux.

We have an underlying issue with the service.  We are hitting a memory limit for the session and getting a lot of errors (which we log to the DB).  However, this is resulting in a stack overflow exception in the connector/net driver which then crashes the whole service.

I am not exactly sure how to repeat, since the exception I see in journalctl for the service gives a stack trace that never escapes the connector code to get to my code!  However, it should not be possible for this to arise, so as well as our underlying issue I see this as a bug in the connector.

What i see is this:
```
Stack overflow.
   at System.Net.Sockets.NetworkStream.Read(Byte[], Int32, Int32)
   at MySql.Data.MySqlClient.TimedStream+<ReadAsync>d__30.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.TimedStream+<ReadAsync>d__30, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<ReadAsync>d__30 ByRef)
   at MySql.Data.MySqlClient.MySqlStream+<ReadFullyAsync>d__31.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.MySqlStream+<ReadFullyAsync>d__31, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<ReadFullyAsync>d__31 ByRef)
   at MySql.Data.MySqlClient.MySqlStream+<LoadPacketAsync>d__32.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.MySqlStream+<LoadPacketAsync>d__32, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<LoadPacketAsync>d__32 ByRef)
   at MySql.Data.MySqlClient.MySqlStream+<ReadPacketAsync>d__30.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.MySqlStream+<ReadPacketAsync>d__30, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<ReadPacketAsync>d__30 ByRef)
   at MySql.Data.MySqlClient.MySqlStream.ReadPacketAsync(Boolean)
   at MySql.Data.MySqlClient.MySqlStream+<SendPacketAsync>d__33.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.MySqlStream+<SendPacketAsync>d__33, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<SendPacketAsync>d__33 ByRef)
   at MySql.Data.MySqlClient.NativeDriver+<ExecutePacketAsync>d__53.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.NativeDriver+<ExecutePacketAsync>d__53, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<ExecutePacketAsync>d__53 ByRef)
   at MySql.Data.MySqlClient.NativeDriver+<CloseAsync>d__43.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.NativeDriver+<CloseAsync>d__43, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<CloseAsync>d__43 ByRef)
   at MySql.Data.MySqlClient.Driver+<DisposeAsync>d__100.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.Driver+<DisposeAsync>d__100, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<DisposeAsync>d__100 ByRef)
   at MySql.Data.MySqlClient.Driver.DisposeAsync(Boolean, Boolean)
   at MySql.Data.MySqlClient.Driver+<CloseAsync>d__77.MoveNext()
```

How to repeat:
As said, I can't see exactly where in my code this is coming from.  The service reads config from the DSB and also logs to it.

We did some packet inspection and it looks like this happens when the request to the service is aborted during the connect phase of the DB call.
[2 Jul 16:39] Adam Conway
Also saw this - this is just a snippet, it kept repeating
```
   at MySql.Data.MySqlClient.Driver+<CloseAsync>d__77.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.Driver+<CloseAsync>d__77, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<CloseAsync>d__77 ByRef)
   at MySql.Data.MySqlClient.Driver.CloseAsync(Boolean)
   at MySql.Data.MySqlClient.NativeDriver+<HandleExceptionAsync>d__31.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.NativeDriver+<HandleExceptionAsync>d__31, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<HandleExceptionAsync>d__31 ByRef)
   at MySql.Data.MySqlClient.NativeDriver.HandleExceptionAsync(MySql.Data.MySqlClient.MySqlException, Boolean)
   at MySql.Data.MySqlClient.NativeDriver+<ExecutePacketAsync>d__53.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.NativeDriver+<ExecutePacketAsync>d__53, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<ExecutePacketAsync>d__53 ByRef)
   at MySql.Data.MySqlClient.NativeDriver.ExecutePacketAsync(MySql.Data.MySqlClient.MySqlPacket, Boolean)
   at MySql.Data.MySqlClient.NativeDriver+<CloseAsync>d__43.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.NativeDriver+<CloseAsync>d__43, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<CloseAsync>d__43 ByRef)
   at MySql.Data.MySqlClient.Driver+<DisposeAsync>d__100.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.Driver+<DisposeAsync>d__100, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<DisposeAsync>d__100 ByRef)
   at MySql.Data.MySqlClient.Driver+<CloseAsync>d__77.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.Driver+<CloseAsync>d__77, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<CloseAsync>d__77 ByRef)
   at MySql.Data.MySqlClient.Driver.CloseAsync(Boolean)
   at MySql.Data.MySqlClient.NativeDriver+<HandleExceptionAsync>d__31.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.NativeDriver+<HandleExceptionAsync>d__31, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<HandleExceptionAsync>d__31 ByRef)
   at MySql.Data.MySqlClient.NativeDriver.HandleExceptionAsync(MySql.Data.MySqlClient.MySqlException, Boolean)
   at MySql.Data.MySqlClient.NativeDriver+<ExecutePacketAsync>d__53.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[MySql.Data.MySqlClient.NativeDriver+<ExecutePacketAsync>d__53, MySql.Data, Version=9.1.0.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d]](<ExecutePacketAsync>d__53 ByRef)
```
[7 Jul 11:47] MySQL Verification Team
Hello Adam,

Thank you for the bug report.
May I request you to please provide a simple test case(c# class) to reproduce this issue at our end?

Regards,
Ashwini Patil