diff --git a/code/default/launcher/web_control.py b/code/default/launcher/web_control.py index 9ef71d96ff..927a907b3c 100644 --- a/code/default/launcher/web_control.py +++ b/code/default/launcher/web_control.py @@ -1057,11 +1057,11 @@ def stop(): xlog.info("launcher web control exited.") -def http_request(url, method="GET"): +def http_request(url, method="GET", timeout=30): proxy_handler = ProxyHandler({}) opener = build_opener(proxy_handler) try: - req = opener.open(url, timeout=30) + req = opener.open(url, timeout=timeout) return req except Exception as e: # xlog.exception("web_control http_request:%s fail:%s", url, e) @@ -1076,7 +1076,7 @@ def confirm_xxnet_not_running(): xlog.debug("start confirm_xxnet_exit url:%s", req_url) for i in range(30): - if http_request(req_url) == False: + if http_request(req_url, timeout=5) == False: xlog.debug("good, xxnet:%s clear!" % host_port) is_xxnet_exit = True break diff --git a/code/default/lib/noarch/front_base/boringssl_wrap.py b/code/default/lib/noarch/front_base/boringssl_wrap.py index bfd05e9b73..841729ba7e 100644 --- a/code/default/lib/noarch/front_base/boringssl_wrap.py +++ b/code/default/lib/noarch/front_base/boringssl_wrap.py @@ -236,7 +236,7 @@ def read(self, bufsiz, flags=0): def write(self, buf, flags=0): return self.send(buf, flags) - def close(self): + def close(self, reason=""): with self._lock: self.running = False if not self.socket_closed: @@ -279,7 +279,7 @@ def close(self): self.socket_closed = True if self._on_close: - self._on_close(self.ip_str, self.sni) + self._on_close(self.ip_str, self.sni, reason=reason) self._on_close = None def __del__(self): diff --git a/code/default/lib/noarch/front_base/http1.py b/code/default/lib/noarch/front_base/http1.py index 412abc0c17..0a56b390e1 100644 --- a/code/default/lib/noarch/front_base/http1.py +++ b/code/default/lib/noarch/front_base/http1.py @@ -159,20 +159,28 @@ def request_task(self, task): start += sended task.set_state("h1_req_sended") + except Exception as e: + self.logger.exception("%s h1_request send:%r inactive_time:%d task.timeout:%d", + self.ip_str, e, time.time() - self.last_recv_time, task.timeout) + self.logger.warn('%s trace:%s', self.ip_str, self.get_trace()) - response = simple_http_client.Response(self.ssl_sock) + self.retry_task_cb(task) + self.task = None + self.close("send fail") + return + try: + response = simple_http_client.Response(self.ssl_sock) response.begin(timeout=timeout) task.set_state("response_begin") - except Exception as e: - self.logger.warn("%s h1_request:%r inactive_time:%d task.timeout:%d", + self.logger.exception("%s h1_request recv:%r inactive_time:%d task.timeout:%d", self.ip_str, e, time.time() - self.last_recv_time, task.timeout) self.logger.warn('%s trace:%s', self.ip_str, self.get_trace()) self.retry_task_cb(task) self.task = None - self.close("down fail") + self.close("recv fail") return task.set_state("h1_get_head") @@ -208,7 +216,7 @@ def request_task(self, task): self.logger.warn("read fail, ip:%s, chunk:%d url:%s task.timeout:%d e:%r", self.ip_str, response.chunked, task.url, task.timeout, e) self.logger.warn('%s trace:%s', self.ip_str, self.get_trace()) - self.close("down fail") + self.close("read fail") return task.put_data(data) diff --git a/code/default/lib/noarch/front_base/http_common.py b/code/default/lib/noarch/front_base/http_common.py index debebaa7dc..501f449f91 100644 --- a/code/default/lib/noarch/front_base/http_common.py +++ b/code/default/lib/noarch/front_base/http_common.py @@ -263,7 +263,7 @@ def close(self, reason): # self.logger.debug("worker.close %s reason:%s", self.ip_str, reason) self.accept_task = False self.keep_running = False - self.ssl_sock.close() + self.ssl_sock.close(reason) if reason not in ["idle timeout", "life end"]: now = time.time() inactive_time = now - self.last_recv_time @@ -319,5 +319,7 @@ def is_life_end(self): return True elif self.processed_tasks > self.config.http2_max_process_tasks: return True + elif self.version == "1.1" and now - self.last_recv_time > self.config.http1_idle_time: + return True else: return False diff --git a/code/default/lib/noarch/front_base/pyopenssl_wrap.py b/code/default/lib/noarch/front_base/pyopenssl_wrap.py index 562f998375..8ee91e5714 100644 --- a/code/default/lib/noarch/front_base/pyopenssl_wrap.py +++ b/code/default/lib/noarch/front_base/pyopenssl_wrap.py @@ -257,14 +257,14 @@ def read(self, bufsiz, flags=0): def write(self, buf, flags=0): return self.sendall(buf, flags) - def close(self): + def close(self, reason=""): if self._makefile_refs < 1: self.running = False if not self.socket_closed: socket.socket.close(self._sock) self.socket_closed = True if self._on_close: - self._on_close(self.ip_str, self.sni) + self._on_close(self.ip_str, self.sni, reason=reason) self._on_close = None else: self._makefile_refs -= 1 diff --git a/code/default/lib/noarch/front_base/ssl_wrap.py b/code/default/lib/noarch/front_base/ssl_wrap.py index d7ef6fca66..bcba121c66 100644 --- a/code/default/lib/noarch/front_base/ssl_wrap.py +++ b/code/default/lib/noarch/front_base/ssl_wrap.py @@ -189,14 +189,14 @@ def read(self, bufsiz, flags=0): def write(self, buf, flags=0): return self.sendall(buf, flags) - def close(self): + def close(self, reason=""): if self._makefile_refs < 1: self.running = False if not self.socket_closed: socket.socket.close(self._sock) self.socket_closed = True if self._on_close: - self._on_close(self.ip_str, self.sni) + self._on_close(self.ip_str, self.sni, reason=reason) else: self._makefile_refs -= 1 diff --git a/code/default/lib/noarch/front_base/tlslite_wrap.py b/code/default/lib/noarch/front_base/tlslite_wrap.py index 1e5354aefb..6596e26e0f 100644 --- a/code/default/lib/noarch/front_base/tlslite_wrap.py +++ b/code/default/lib/noarch/front_base/tlslite_wrap.py @@ -127,14 +127,14 @@ def read(self, bufsiz, flags=0): def write(self, buf, flags=0): return self.sendall(buf, flags) - def close(self): + def close(self, reason=""): if self._makefile_refs < 1: self.running = False if not self.socket_closed: socket.socket.close(self._sock) self.socket_closed = True if self._on_close: - self._on_close(self.ip_str, self.sni) + self._on_close(self.ip_str, self.sni, reason=reason) else: self._makefile_refs -= 1 diff --git a/code/default/lib/noarch/simple_http_client.py b/code/default/lib/noarch/simple_http_client.py index ae8bd6be46..f30f4abe0f 100644 --- a/code/default/lib/noarch/simple_http_client.py +++ b/code/default/lib/noarch/simple_http_client.py @@ -149,7 +149,7 @@ def recv(self, to_read=8192, timeout=30.0): while time.time() < end_time: try: return self.sock.recv(to_read) - except socket.error as e: + except (BlockingIOError, socket.error) as e: if e.errno in [2, 11, 35, 10035]: time_left = end_time - time.time() if time_left < 0: @@ -314,7 +314,7 @@ def _read_size(self, read_len, timeout): try: nbytes = self.sock.recv_into(view[out_len:], to_read) - except socket.error as e: + except (BlockingIOError, socket.error) as e: if e.errno in [2, 11, 35, 10035]: time_left = start_time + timeout - time.time() if time_left < 0: diff --git a/code/default/version.txt b/code/default/version.txt index 885bc9f72d..f05e61d963 100644 --- a/code/default/version.txt +++ b/code/default/version.txt @@ -1 +1 @@ -5.8.1 \ No newline at end of file +5.8.3 \ No newline at end of file diff --git a/code/default/x_tunnel/local/base_container.py b/code/default/x_tunnel/local/base_container.py index 88c035eecc..005761ea1e 100644 --- a/code/default/x_tunnel/local/base_container.py +++ b/code/default/x_tunnel/local/base_container.py @@ -435,7 +435,7 @@ def close_sock(self, sock, reason): try: conn = self.sock_conn_map[sock] - self.xlog.info("close conn:%d", conn.conn_id) + # self.xlog.info("close conn:%d", conn.conn_id) self.remove_sock(sock) conn.transfer_peer_close(reason) diff --git a/code/default/x_tunnel/local/seley_front/ip_manager.py b/code/default/x_tunnel/local/seley_front/ip_manager.py index 9372f15c40..0e5b92b560 100644 --- a/code/default/x_tunnel/local/seley_front/ip_manager.py +++ b/code/default/x_tunnel/local/seley_front/ip_manager.py @@ -45,19 +45,25 @@ def load(self): ip_hosts = {} for domain_port, host_info in domain_hosts.items(): + if not host_info.get("key"): + continue + ip, port = utils.get_ip_port(domain_port) if not utils.check_ip_valid(ip): try: info = socket.getaddrinfo(ip, port, socket.AF_UNSPEC, socket.SOCK_STREAM) - af, socktype, proto, canonname, sa = info[0] - ip = sa[0] + for af, socktype, proto, canonname, sa in info: + ip = sa[0] + + ip_str = utils.get_ip_str(ip, port) + ip_hosts[ip_str] = host_info except socket.gaierror: - pass + ip_hosts[domain_port] = host_info + else: + ip_hosts[domain_port] = host_info - ip_str = utils.get_ip_str(ip, port) - ip_hosts[ip_str] = host_info self.hosts = ip_hosts def _get_ip_info(self, ip_str): @@ -74,6 +80,7 @@ def _get_ip_info(self, ip_str): def get_ip_sni_host(self): now = time.time() + ip_str = None best_info = None best_speed = 0 @@ -94,14 +101,14 @@ def get_ip_sni_host(self): if now - info["last_try"] > 30 * 60: best_info = info - xlog.debug("get_ip_sni_host last_try %s", ip_str) + # xlog.debug("get_ip_sni_host last_try %s", ip_str) break speed = self.get_speed(ip_str) if speed > best_speed: best_speed = speed best_info = info - xlog.debug("get_ip_sni_host best speed %s", ip_str) + # xlog.debug("get_ip_sni_host best speed %s", ip_str) if not best_info: return None, None, None diff --git a/code/default/x_tunnel/local/seley_front/rc4_wrap.py b/code/default/x_tunnel/local/seley_front/rc4_wrap.py index e89d6d05a0..e0b0a803c3 100644 --- a/code/default/x_tunnel/local/seley_front/rc4_wrap.py +++ b/code/default/x_tunnel/local/seley_front/rc4_wrap.py @@ -132,14 +132,14 @@ def read(self, bufsiz, flags=0): def write(self, buf, flags=0): return self.sendall(buf, flags) - def close(self): + def close(self, reason=""): if self._makefile_refs < 1: self.running = False if not self.socket_closed: socket.socket.close(self._sock) self.socket_closed = True if self._on_close: - self._on_close(self.ip_str, self.sni) + self._on_close(self.ip_str, self.sni, reason=reason) else: self._makefile_refs -= 1