zoukankan      html  css  js  c++  java
  • 客户端关闭写后,继续写数据socket.error: [Errno 32] Broken pipe

    Broken pipe出现的时机是:在一个 RST 的套接字继续写数据,就会出现Broken pipe。
    下面来模拟 Broken pipe 的情况,服务端代码非常简单,几乎什么都没做,完整的代码见:
    node2:/root#tcpdump -S -i eth1 '((tcp) and  (host 192.168.137.3) and (port 8080) )'
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
    00:27:57.885816 IP node2.56882 > node1.webcache: Flags [S], seq 2109269905, win 14600, options [mss 1460,sackOK,TS val 11592824 ecr 0,nop,wscale 7], length 0
    00:27:57.886043 IP node1.webcache > node2.56882: Flags [S.], seq 2673199318, ack 2109269906, win 14480, options [mss 1460,sackOK,TS val 1448873 ecr 11592824,nop,wscale 6], length 0
    00:27:57.886055 IP node2.56882 > node1.webcache: Flags [.], ack 2673199319, win 115, options [nop,nop,TS val 11592824 ecr 1448873], length 0
    00:27:57.886125 IP node2.56882 > node1.webcache: Flags [P.], seq 2109269906:2109269915, ack 2673199319, win 115, options [nop,nop,TS val 11592824 ecr 1448873], length 9
    00:27:57.886163 IP node2.56882 > node1.webcache: Flags [F.], seq 2109269915, ack 2673199319, win 115, options [nop,nop,TS val 11592824 ecr 1448873], length 0
    00:27:57.886186 IP node1.webcache > node2.56882: Flags [.], ack 2109269915, win 227, options [nop,nop,TS val 1448873 ecr 11592824], length 0
    00:27:57.886463 IP node1.webcache > node2.56882: Flags [P.], seq 2673199319:2673199337, ack 2109269916, win 227, options [nop,nop,TS val 1448873 ecr 11592824], length 18
    00:27:57.886475 IP node2.56882 > node1.webcache: Flags [R], seq 2109269916, win 0, length 0
    00:27:57.886501 IP node1.webcache > node2.56882: Flags [F.], seq 2673199337, ack 2109269916, win 227, options [nop,nop,TS val 1448873 ecr 11592824], length 0
    00:27:57.886507 IP node2.56882 > node1.webcache: Flags [R], seq 2109269916, win 0, length 0
    
    node2:/root/test#cat t13.py 
    import socket
    import struct
    import time
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 1, 0))
    s.connect(("192.168.137.2",8080))
    s.send('111111111')
    s.shutdown(2)
    s.send('111111111')
    s.send('111111111')
    s.send('111111111')
    
    node2:/root/test#python t13.py 
    Traceback (most recent call last):
      File "t13.py", line 10, in <module>
        s.send('111111111')
    socket.error: [Errno 32] Broken pipe
  • 相关阅读:
    Mycat的server.xml配置
    Docker构建Mycat(单节点)
    Mycat相关概念解读
    Mycat简介及适用场景
    SpringBoot整合WebService
    SpringBoot事务简单操作及手动回滚
    对事务及其注解@Transactional的解读
    git将某分支的某次提交合并到另一分支
    SpringBoot快速支持国际化i18n
    SpringBoot多数据源自动切换
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348455.html
Copyright © 2011-2022 走看看