question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenAsync throws System.IO.EndOfStreamException

See original GitHub issue

Sometimes 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:

https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/Serialization/MySqlSession.cs#L140

        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:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bgraingercommented, Oct 27, 2016

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 inside AggregateException. 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!

1reaction
caleblloydcommented, Oct 27, 2016

Looks like the problem is that System.AggregateException is getting thrown, and not caught in TryPingAsync

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found