socketException之broken pipe

周末在做数据库迁移时,DBA在插数据到某个大表时,锁表导致应用程序报“Broken pipe”的错误

socketException之broken pipe

 

I know that broken pipe error is thrown when the socket on the peer side is closed.

But, in my test I have noted that an immediate 'send' call on this side when the peer side is closed doesn't always lead to a broken pipe error.

After closing the socket on peer side (I have tried clean closing by calling close and also abnormal closing by killing the peer), if I try to send 40 bytes, then I don't get a broken pipe, but, if I try to send 40000 bytes then it immediately gives broken pipe error.

总体来说是因为对端socket已经关闭,导致broken pipe (断开的管道(非正常关闭socket引发的错误))

以下三篇文章介绍的不错

https://blog.****.net/wind19/article/details/8049108

https://stackoverflow.com/questions/4584904/what-causes-the-broken-pipe-error 

https://www.cnblogs.com/metoy/p/6565486.html