thrift timeout for long run call: thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

让人想犯罪 __ 提交于 2019-12-12 05:48:48

问题


I've build some a rpc service using thrift. It may run long time (minutes to hours) for each call. I've set the thrift timeout to 2 days.

transport = TSocket.TSocket(self.__host, self.__port)
transport.setTimeout(2 * 24 * 60 * 60 * 1000)

But the thrift always closes connection after about 600s, with the following exception:

thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

Is there's any other timeout should i set? (python, thrift server: windows; client: ubuntu)


回答1:


The Thrift Transport connection is being disconnected. This could be due to network issues or remote service restart or time out issues. Whenever any call is made after a disconnect this results in TTransportException. This problem can be solved by reconnecting to the remote service. Try using this, invoking it before making a remote service call.

def repoen_transport():
    try:
        if not transport.isOpen():
            transport.open()
    except Exception, msg:
        print >> sys.stderr.write("Error reopening transport {}".format(msg))


来源:https://stackoverflow.com/questions/45301510/thrift-timeout-for-long-run-call-thrift-transport-ttransport-ttransportexceptio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!