mirror of
https://github.com/alexbers/mtprotoproxy.git
synced 2026-03-14 07:13:09 +00:00
better handling for server-side socket closing in connection pool
This commit is contained in:
@@ -483,7 +483,7 @@ myrandom = MyRandom()
|
||||
|
||||
|
||||
class TgConnectionPool:
|
||||
MAX_CONNS_IN_POOL = 64
|
||||
MAX_CONNS_IN_POOL = 16
|
||||
|
||||
def __init__(self):
|
||||
self.pools = {}
|
||||
@@ -500,6 +500,16 @@ class TgConnectionPool:
|
||||
timeout=config.TG_CONNECT_TIMEOUT)
|
||||
return reader_tgt, writer_tgt
|
||||
|
||||
def is_conn_dead(self, reader, writer):
|
||||
if writer.transport.is_closing():
|
||||
return True
|
||||
raw_reader = reader
|
||||
while hasattr(raw_reader, 'upstream'):
|
||||
raw_reader = raw_reader.upstream
|
||||
if raw_reader.at_eof():
|
||||
return True
|
||||
return False
|
||||
|
||||
def register_host_port(self, host, port, init_func):
|
||||
if (host, port, init_func) not in self.pools:
|
||||
self.pools[(host, port, init_func)] = []
|
||||
@@ -519,8 +529,9 @@ class TgConnectionPool:
|
||||
continue
|
||||
|
||||
reader, writer, *other = task.result()
|
||||
if writer.transport.is_closing():
|
||||
if self.is_conn_dead(reader, writer):
|
||||
self.pools[(host, port, init_func)].remove(task)
|
||||
writer.transport.abort()
|
||||
continue
|
||||
|
||||
if not ret:
|
||||
|
||||
Reference in New Issue
Block a user