Closed accjiyun closed 4 years ago
Use thrift_connector to resolve this problem, or if existing client timeout, initialize a client again. A client instance always uses bonded transport (socket) and it would not remove it even it is timeout.
@ethe thrift_connector 接口似乎不太友好,ClientPool() 不方便直接指定transport和protocol
class ThriftPyTFramedClient(ThriftPyBaseClient):
@classmethod
def get_protoco_factory(self):
from thriftpy2.protocol import TBinaryProtocolFactory
return TBinaryProtocolFactory().get_protocol
@classmethod
def get_transport_factory(self):
from thriftpy2.transport import TFramedTransportFactory
return TFramedTransportFactory().get_transport
pool = connection_pool.ClientPool(
getattr(self.service_thrift, self.service),
host, int(port), 1000,
connection_class=ThriftPyTFramedClient
)
Yes, for now, it only supports define a subclass to ThriftPyBaseClient
. I will consider to improve it.
版本号:0.4.10
当thrift client连接时间超过设置的超时阈值后,连接并没有断开,而是将本次的超时结果数据放到了缓存中,并且覆盖了下次访问thrift server的返回结果。
举个例子: thrift server:
正常情况下,依次访问返回结果如下: client.get(1) 得到的结果是1 client.get(2) 得到的结果是2
如果在第一步client.get(1) 超时返回结果为空,第二次访问client.get(2) 得到的是1
我的连接方式和超时错误如下: