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.Net.Sockets.SocketException: Broken pipe"

See original GitHub issue

Sometimes i’m receiving SocketException when calling _con.OpenAsync(cancellationToken).

Follow the stack:

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. ---> System.Net.Sockets.SocketException: Broken pipe
   at MySql.Data.SocketAwaitable.GetResult()
   at MySql.Data.Protocol.Serialization.SocketByteHandler.<DoWriteBytesAsync>d__4.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.Threading.Tasks.ValueTask`1.get_Result()
   at MySql.Data.ValueTaskExtensions.ContinueWith[T,TResult](ValueTask`1 valueTask, Func`2 continuation)
   at MySql.Data.Protocol.Serialization.ProtocolUtility.WritePacketAsync(IByteHandler byteHandler, Int32 sequenceNumber, ArraySegment`1 contents, IOBehavior ioBehavior)
   at MySql.Data.Protocol.Serialization.ProtocolUtility.WritePayloadAsync(IByteHandler byteHandler, Func`1 getNextSequenceNumber, ArraySegment`1 payload, IOBehavior ioBehavior)
   at MySql.Data.Serialization.MySqlSession.TryAsync[TArg](Func`3 func, TArg arg, IOBehavior ioBehavior, CancellationToken cancellationToken)
   at MySql.Data.Serialization.MySqlSession.SendAsync(PayloadData payload, IOBehavior ioBehavior, CancellationToken cancellationToken)
   at MySql.Data.Serialization.MySqlSession.<TryPingAsync>d__24.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 MySql.Data.MySqlClient.ConnectionPool.<GetSessionAsync>d__0.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 MySql.Data.MySqlClient.MySqlConnection.<CreateSessionAsync>d__57.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 MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__11.MoveNext()
   --- End of inner exception stack trace ---
   at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__11.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)

Maybe await SendAsync(PingPayload.Create(), ioBehavior, cancellationToken).ConfigureAwait(false); should be inside try catch to?

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
caleblloydcommented, Dec 15, 2016

Broken pipe typically occurs either when you either unplug a network cable or encounter a NAT timeout. This happens because the server has closed the connection and sent a TCP FIN packet, but the client never got the FIN packet.

Since the client still thinks the connection is open, it continues the TCP conversation with the server from where it left off. The server has closed the connection already though, so it sends a RST packet. This causes a broken pipe exception.

It’s most likely NAT timeout or your network is going away and then coming back.

0reactions
naughtyGitCatcommented, Mar 8, 2022

we do not use nat, but physical host with static ip , the latest version does not fix too

mysql conn string is

    "MySQL": {
      "ReadWriteURI": "server=XXXXXX;port=3306;user=XXXXX;password=XXXXX;database=XXXXX",
      "ReadOnlyURI": "server=YYYYY;port=3306;user=YYYY;password=YYYY;database=YYYY;DefaultCommandTimeout=188;SslMode=None;MaximumPoolsize=1588;MinimumPoolSize=8;ConnectionReset=false;ConnectionIdlePingTime=2;ConnectionIdleTimeout=88"
    },

@caleblloyd

Read more comments on GitHub >

github_iconTop Results From Across the Web

Socket with .NET Core 3.1: Connection breaks running on ...
Unhandled exception. System.Net.Sockets.SocketException (32): Broken pipe at System.Net.Sockets.Socket.Send(Byte\[\] buffer) at OnkyoEiscp.
Read more >
How to fix java.net.SocketException: Broken pipe?
I am using apache commons http client to call url using post method to post the parameters and it is throwing the below...
Read more >
Untitled
... OpenAsync throws "System.Net.Sockets.SocketException: Broken pipe" - GitHub WebApr 18, 2017 · An unhandled exception occurs when the application code ...
Read more >
Untitled
NET Provider for SQL Server https://www.qfs.de/en/qf-test-manual/lc/manual-en-exceptions.html OpenAsync throws "System.Net.Sockets.SocketException: Broken …
Read more >
(NOT SOLVED) java.net.SocketException: Broken pipe
Hello, In my app I'm trying to send a flac file to google for speech recognition. I'm using a thread to do the...
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