Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAsync throws System.IO.EndOfStreamException #124

Closed
alanprot opened this issue Oct 27, 2016 · 5 comments
Closed

OpenAsync throws System.IO.EndOfStreamException #124

alanprot opened this issue Oct 27, 2016 · 5 comments
Assignees

Comments

@alanprot
Copy link

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?

@alanprot
Copy link
Author

I believe that because of that it was not possible to Dispose and remove some bad connection of my Connection Pool.

https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/MySqlClient/ConnectionPool.cs#L29

@caleblloyd
Copy link
Contributor

caleblloyd commented Oct 27, 2016

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

@alanprot
Copy link
Author

Yes...
I missed that!

@bgrainger bgrainger self-assigned this Oct 27, 2016
@bgrainger
Copy link
Member

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!

@GomesNayagam
Copy link

GomesNayagam commented Nov 3, 2017

[bgrainger] Moved to #388.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants