in dubbo/connection/connections.py [0:0]
def _check_conn(self, host):
"""
对连接进行检查,查看是否超时或者已经达到最大的超时次数
:param host:
:return:
"""
conn = self._connection_pool[host]
# 如果未达到最大的超时时间,则不进行任何操作
if time.time() - conn.last_active <= TIMEOUT_IDLE:
return
# 达到最大的超时次数,对此连接进行重连
if self.client_heartbeats[host] >= TIMEOUT_MAX_TIMES:
self._new_connection(host)
self.client_heartbeats[host] = 0
conn.close() # 关闭旧的连接
logger.debug('{} timeout and reconnected by client.'.format(host))
# 未达到最大的超时次数,超时次数+1且发送心跳包
else:
self.client_heartbeats[host] += 1
invoke_id = get_invoke_id()
req = CLI_HEARTBEAT_REQ_HEAD + list(bytearray(pack('!q', invoke_id))) + CLI_HEARTBEAT_TAIL
conn.write(bytearray(req))
logger.debug('Send ❤ request for invoke_id {}, host={}'.format(invoke_id, host))