From 339c1ccee25b1b2157924324b22374c6514a4313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=B4=E5=A8=83=E9=85=B1?= Date: Mon, 3 Jul 2017 14:49:10 +0800 Subject: [PATCH] fix connections ref --- shadowsocks/tcprelay.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index ca431e6..506e1ce 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -138,6 +138,7 @@ class TCPRelayHandler(object): self._remote_udp = False self._config = config self._dns_resolver = dns_resolver + self._add_ref = 0 if not self._create_encryptor(config): return @@ -217,6 +218,7 @@ class TCPRelayHandler(object): self._update_activity() self._server.add_connection(1) self._server.stat_add(self._client_address[0], 1) + self._add_ref = 1 self.speed_tester_u = SpeedTester(config.get("speed_limit_per_con", 0)) self.speed_tester_d = SpeedTester(config.get("speed_limit_per_con", 0)) self._recv_u_max_size = BUF_SIZE @@ -1159,8 +1161,9 @@ class TCPRelayHandler(object): self._encryptor = None self._dns_resolver.remove_callback(self._handle_dns_resolved) self._server.remove_handler(self) - self._server.add_connection(-1) - self._server.stat_add(self._client_address[0], -1) + if self._add_ref > 0: + self._server.add_connection(-1) + self._server.stat_add(self._client_address[0], -1) class TCPRelay(object): def __init__(self, config, dns_resolver, is_local, stat_callback=None, stat_counter=None):