OpenAsync throws System.IO.EndOfStreamException
See original GitHub issueSometimes i’m receiving EndOfStreamException when calling _con.OpenAsync(cancellationToken) maybe due a timeout.
System.AggregateException: One or more errors occurred. (Attempted to read past the end of the stream.) ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at MySql.Data.ValueTaskExtensions.<>c__DisplayClass0_0`2.<ContinueWith>b__0(Task`1 task)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.Serialization.MySqlSession.TryAsyncContinuation(Task`1 task)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at MySql.Data.Serialization.MySqlSession.<TryPingAsync>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.ConnectionPool.<GetSessionAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.MySqlConnection.<CreateSessionAsync>d__54.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__11.MoveNext()
I notice that this exception is handled at:
public async Task<bool> TryPingAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
{
await SendAsync(PingPayload.Create(), ioBehavior, cancellationToken).ConfigureAwait(false);
try
{
var payload = await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
OkPayload.Create(payload);
return true;
}
catch (EndOfStreamException)
{
}
catch (SocketException)
{
}
return false;
}
Maybe await SendAsync(PingPayload.Create(), ioBehavior, cancellationToken).ConfigureAwait(false)
; should be inside try catch to?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why is my program terminated when calling "OpenAsync()"?
In short, exceptions thrown when calling an async void method isn't handled the same way as awaiting a Task and will crash the...
Read more >MySQL Connector/NET Release Notes
On systems running .NET 6, Connector/NET could throw an exception when trying to perform an equality check involving type Datetime.Date.
Read more >DbConnection.OpenAsync Method (System.Data.Common)
This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored...
Read more >MySqlConnector vs MySql.Data
MySqlConnector adds full distributed transaction support (for client code using System.Transactions.Transaction ), while Connector/NET uses regular database ...
Read more >错误记录——fail: Microsoft.AspNetCore.Server.Kestrel[13]
System.IO.EndOfStreamException: Attempted to read past the end of the stream. 4 at MySql.Data.MySqlClient.MySqlStream.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed in 0.6.1.
I wasn’t able to reproduce the precise crash (in the original call stack you posted), but I did fix the problem of
EndOfStreamException
(or any exception) being unnecessarily wrapped insideAggregateException
. Fixing this should allow the exception to go through the regular exception-handling code path, which should resolve your issue. If it’s not fixed, please reopen this case!Looks like the problem is that
System.AggregateException
is getting thrown, and not caught inTryPingAsync