diff --git a/code/default/launcher/web_control.py b/code/default/launcher/web_control.py index 0fb2f662ab..634cd366d1 100644 --- a/code/default/launcher/web_control.py +++ b/code/default/launcher/web_control.py @@ -61,6 +61,13 @@ module_menus = {} +class FakeHttpHandler(simple_http_server.HttpServerHandler): + def handle_one_request(self): + # This function will replace simple_http_server HttpHandler.handle_one_request to hold all http requests. + # Doing this is to simulate bug. + self.close_connection = 0 + + class Http_Handler(simple_http_server.HttpServerHandler): deploy_proc = None @@ -244,6 +251,10 @@ def do_GET(self): return self.req_log_handler() elif url_path == "/keep_log": return self.req_keep_log_handler() + elif url_path == "/suck_threads": + return self.req_suck_threads() + elif url_path == "/hold_8085": + return self.req_hold_8085() elif url_path == '/update': self.req_update_handler() elif url_path == '/config_proxy': @@ -797,6 +808,16 @@ def req_keep_log_handler(self): mimetype = 'text/plain' self.send_response(mimetype, data) + def req_suck_threads(self): + self.send_response('text/plain', "Start suck threads") + while True: + threading.Thread(target=time.sleep, args=(1000,)).start() + + def req_hold_8085(self): + global server + self.send_response('text/plain', "Hold 8085") + server.handler = FakeHttpHandler + def req_log_handler(self): req = urlparse(self.path).query reqs = self.unpack_reqs(parse_qs(req, keep_blank_values=True)) diff --git a/code/default/lib/noarch/front_base/connect_manager.py b/code/default/lib/noarch/front_base/connect_manager.py index 4a6dad3bed..61fb7dbe12 100644 --- a/code/default/lib/noarch/front_base/connect_manager.py +++ b/code/default/lib/noarch/front_base/connect_manager.py @@ -165,6 +165,7 @@ def __init__(self, logger, config, connect_creator, ip_manager, check_local_netw self._waiting_num_lock = threading.Lock() self._connection_waiting_num = 0 self.no_ip_lock = threading.Lock() + self.no_ip_time = 0 # after new created ssl_sock timeout(50 seconds) # call the callback. @@ -259,7 +260,7 @@ def _connect_thread(self, sleep_time=0): time.sleep(sleep_time) try: - while self.running and self._need_more_ip(): + while self.running and self._need_more_ip() and time.time() - self.no_ip_time > 10: if self.new_conn_pool.qsize() > self.config.https_connection_pool_max: break @@ -275,6 +276,7 @@ def _connect_process(self): try: ip_str, sni, host = self.ip_manager.get_ip_sni_host() if not ip_str: + self.no_ip_time = time.time() with self.no_ip_lock: # self.logger.warning("not enough ip") time.sleep(10) diff --git a/code/default/lib/noarch/simple_http_server.py b/code/default/lib/noarch/simple_http_server.py index a6108686d2..fbd2769849 100644 --- a/code/default/lib/noarch/simple_http_server.py +++ b/code/default/lib/noarch/simple_http_server.py @@ -658,7 +658,7 @@ def check_listen_port_or_reset(self): if res: return - self.logger.warn("Listen %s:%d check failed", ip, port) + self.logger.warn("Listen %s:%d check failed, try restart listening", ip, port) self.shutdown() time.sleep(3) self.start() diff --git a/code/default/smart_router/local/smart_route.py b/code/default/smart_router/local/smart_route.py index 05282cfaad..45e169462b 100644 --- a/code/default/smart_router/local/smart_route.py +++ b/code/default/smart_router/local/smart_route.py @@ -239,7 +239,7 @@ def do_socks(sock, host, port, client_address, left_buf=b""): raise XTunnelNotRunning() try: - conn_id = g.x_tunnel.proxy_session.create_conn(sock, host, port) + conn_id = g.x_tunnel.proxy_session.create_conn(sock, host, port, True) except Exception as e: xlog.warn("do_sock to %s:%d, x_tunnel fail:%r", host, port, e) raise XTunnelNotRunning() diff --git a/code/default/version.txt b/code/default/version.txt index d1cf0f3227..9b4bab7a7e 100644 --- a/code/default/version.txt +++ b/code/default/version.txt @@ -1 +1 @@ -5.7.6 \ No newline at end of file +5.7.7 \ No newline at end of file diff --git a/code/default/x_tunnel/local/proxy_session.py b/code/default/x_tunnel/local/proxy_session.py index 00087f955b..613a6af7b2 100644 --- a/code/default/x_tunnel/local/proxy_session.py +++ b/code/default/x_tunnel/local/proxy_session.py @@ -431,7 +431,7 @@ def login_session(self): return False - def create_conn(self, sock, host, port): + def create_conn(self, sock, host, port, log=False): if not self.running: xlog.debug("session not running, try to connect") time.sleep(1) @@ -457,6 +457,8 @@ def create_conn(self, sock, host, port): min(g.config.concurent_thread_num - g.config.min_on_road, self.target_on_roads + 5) self.trigger_more() + if log: + xlog.info("Connect to %s:%d conn:%d", host, port, conn_id) return conn_id # Called by stop @@ -1143,7 +1145,7 @@ def login_process(): return True -def create_conn(sock, host, port): +def create_conn(sock, host, port, log=False): if not (g.config.login_account and g.config.login_password): time.sleep(1) return False @@ -1154,7 +1156,7 @@ def create_conn(sock, host, port): else: time.sleep(1) - return g.session.create_conn(sock, host, port) + return g.session.create_conn(sock, host, port, log) def update_quota_loop():