python - thrift error: [Errno 104] Connection reset by peer错误

查看:896
本文介绍了python - thrift error: [Errno 104] Connection reset by peer错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

thrift搭起来之后测试一切正常,但是过一段时间就会在日志里面报[Errno 104] Connection reset by peer错误, 但是如果这时候连thrift又一切正常,又能重新记录正确的日志.
日志如下:

[2017-07-20 15:21:40,818 INFO]: [thrift_api.<module>()]: [RPC SERVER]: starting the server...
[2017-07-20 15:21:58,457 INFO]: [thrift_api.infomation_extend_eb_data()]: [RPC SERVER]: Get ebusiness_data token:cbef95c048ea42e689c9b598552fff25 env: data_type:basic check_token: token_time:...[DONE]
[2017-07-20 15:43:03,172 ERROR]: [TServer.handle()]: [Errno 104] Connection reset by peer
Traceback (most recent call last):
  File "/opt/services/venv/lib/python2.7/site-packages/thrift/server/TServer.py", line 127, in handle
    self.processor.process(iprot, oprot)
  File "../thrift_service_src/ThriftService.py", line 835, in process
    (name, type, seqid) = iprot.readMessageBegin()
  File "/opt/services/venv/lib/python2.7/site-packages/thrift/protocol/TBinaryProtocol.py", line 126, in readMessageBegin
    sz = self.readI32()
  File "/opt/services/venv/lib/python2.7/site-packages/thrift/protocol/TBinaryProtocol.py", line 206, in readI32
    buff = self.trans.readAll(4)
  File "/opt/services/venv/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 58, in readAll
    chunk = self.read(sz - have)
  File "/opt/services/venv/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 159, in read
    self.__rbuf = StringIO(self.__trans.read(max(sz, self.__rbuf_size)))
  File "/opt/services/venv/lib/python2.7/site-packages/thrift/transport/TSocket.py", line 105, in read
    buff = self.handle.recv(sz)
error: [Errno 104] Connection reset by peer
[2017-07-20 15:45:29,168 INFO]: [thrift_api.infomation_extend_eb_data()]: [RPC SERVER]: Get ebusiness_data token:cbef95c048ea42e689c9b598552fff25  env: data_type:basic check_token: token_time:...[DONE]

启动部分代码如下:

if __name__ == "__main__":
    # 设定端口
    start_port_num = 8002
    if len(sys.argv) == 2:
        start_port_num = int(sys.argv[1])

    # 配置服务
    handler = ThriftInforExtendApi()
    processor = ThriftService.Processor(handler)
    # transport = TSocket.TServerSocket(port=start_port_num, host='localhost')
    transport = TSocket.TServerSocket(port=start_port_num)

    transport_factory = TTransport.TBufferedTransportFactory()
    protocol_factory = TBinaryProtocol.TBinaryProtocolFactory()

    # 配置服务器
    server = TServer.TThreadedServer(processor, transport, transport_factory, protocol_factory)
    # 启动服务
    LOG.info("[RPC SERVER]: starting the server...")
    server.serve()

解决方案

这个异常是由glibc里抛出的异常,是TCP协议定的。

异常是由于,接收方已经关闭了连接,而发送方不知道,这样发送方往接收方发数据的时候,接收方的TCP接到这个消息,说这个连接已经关闭了白了你一眼说重来(REST),叫你取号排队重新来。这时候就会有两种情况:

  1. 我重新握手,重新来,啥事没有,一切照旧。

  2. 我就不听你的,我再发一次包,然后对方就直接给你Broken pipe,吐一口痰给你。

所以,我猜,发送方为啥不知道接收方把socket close了是你这个问题的答案。

这篇关于python - thrift error: [Errno 104] Connection reset by peer错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆