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

InvalidOperationException thrown while opening a connection #476

Closed
ddunkin opened this issue Apr 12, 2018 · 2 comments
Closed

InvalidOperationException thrown while opening a connection #476

ddunkin opened this issue Apr 12, 2018 · 2 comments
Labels

Comments

@ddunkin
Copy link
Contributor

ddunkin commented Apr 12, 2018

System.InvalidOperationException: The operation is not allowed on non-connected sockets.
   at System.Net.Sockets.TcpClient.GetStream()
   at MySqlConnector.Core.ServerSession.<OpenTcpSocketAsync>d__69.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.ServerSession.<ConnectAsync>d__56.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.ConnectionPool.<GetSessionAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySql.Data.MySqlClient.MySqlConnection.<CreateSessionAsync>d__83.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__25.MoveNext()

Running MySqlConnector 0.36.1 on .NET Framework 4.7.

This network occasionally has connectivity problems.

@bgrainger bgrainger added the bug label Apr 12, 2018
@bgrainger
Copy link
Member

AFAICT, tcpClient.ConnectAsync (

await tcpClient.ConnectAsync(ipAddress, cs.Port).ConfigureAwait(false);
) succeeded (no SocketException was thrown) but then tcpClient.Client.Connected was false (so GetStream threw). The most likely explanation seems to be that there's a race with the callback passed to cancellationToken.Register and it closed the socket after ConnectAsync completed successfully.

We should check m_socket.Connected and throw a MySqlException.

@bgrainger
Copy link
Member

Fixed in 0.40.0.

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

No branches or pull requests

2 participants