Skip to content

Commit

Permalink
5.5.1 fix lost connection issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-X-Net committed Aug 5, 2023
1 parent 1a8e37e commit 62862fa
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 200 deletions.
17 changes: 16 additions & 1 deletion code/default/launcher/web_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def do_GET(self):
sys_platform.on_quit()
elif url_path == "/debug":
self.req_debug_handler()
elif url_path == "/mem_info":
self.req_mem_info_handler()
elif url_path == "/gc":
self.req_gc_handler()
elif url_path == '/restart':
Expand Down Expand Up @@ -577,7 +579,7 @@ def req_config_handler(self):
data = '{"res":"success"}'
else:
data = '{"res":"fail"}'
elif reqs['cmd'] == ['get_version']:
elif reqs['cmd'] == 'get_version':
current_version = update_from_github.current_version()
data = '{"current_version":"%s"}' % current_version

Expand Down Expand Up @@ -815,6 +817,19 @@ def req_gc_handler(self):
self.send_response("text/plain", "gc collected, count:%d,%d,%d" % count)

def req_debug_handler(self):
req = urlparse(self.path).query
reqs = parse_qs(req, keep_blank_values=True)

dat = ""
try:
dat += "thread num:%d<br>" % threading.active_count()

except Exception as e:
xlog.exception("debug:%r", e)

self.send_response("text/plain", dat)

def req_mem_info_handler(self):
global mem_stat
req = urlparse(self.path).query
reqs = parse_qs(req, keep_blank_values=True)
Expand Down
12 changes: 11 additions & 1 deletion code/default/lib/noarch/xlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import threading
import json
import shutil
from os.path import join

from six import string_types

Expand Down Expand Up @@ -49,6 +50,12 @@ def __init__(self, name, buffer_size=0, file_name=None, roll_num=1,
else:
self.start_log = None

if log_path and os.path.exists(join(log_path, "keep_log.txt")):
self.info("keep log")
self.keep_log = True
else:
self.keep_log = False

if log_path and save_warning_log:
self.warning_log_fn = os.path.join(log_path, "%s_warning.log" % (name))
self.warning_log = open(self.warning_log_fn, "a")
Expand All @@ -68,6 +75,9 @@ def set_buffer(self, buffer_size):
pass

def reset_log_files(self):
if self.keep_log:
return

if self.start_log:
self.start_log.close()
self.start_log = None
Expand Down Expand Up @@ -193,7 +203,7 @@ def log(self, level, console_color, html_color, fmt, *args, **kwargs):
pass
self.start_log_num += 1

if self.start_log_num > self.save_start_log:
if self.start_log_num > self.save_start_log and not self.keep_log:
self.start_log.close()
self.start_log = None

Expand Down
2 changes: 2 additions & 0 deletions code/default/smart_router/local/proxy_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ def handle(self):

except socket.error as e:
xlog.warn('socks handler read error:%r', e)
self.conn.close()
except Exception as e:
xlog.exception("any err:%r", e)
self.conn.close()

def read_null_end_line(self):
sock = self.conn
Expand Down
2 changes: 1 addition & 1 deletion code/default/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.5.0
5.5.1
6 changes: 3 additions & 3 deletions code/default/x_tunnel/local/base_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def add_sock(self, sock, conn):
if sock in self.sock_conn_map:
return

self.xlog.debug("add sock conn:%d", conn.conn_id)
# self.xlog.debug("add sock conn:%d", conn.conn_id)
self.sock_conn_map[sock] = conn
try:
self.select2.register(sock, selectors.EVENT_READ, conn)
Expand All @@ -371,8 +371,8 @@ def remove_sock(self, sock):

try:
self.select2.unregister(sock)
conn = self.sock_conn_map[sock]
self.xlog.debug("remove sock conn:%d", conn.conn_id)
# conn = self.sock_conn_map[sock]
# self.xlog.debug("remove sock conn:%d", conn.conn_id)
del self.sock_conn_map[sock]
except Exception as e:
self.xlog.warn("ConnectionReceiving remove sock e:%r", e)
Expand Down
1 change: 1 addition & 0 deletions code/default/x_tunnel/local/cloudflare_front/ip_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def report_connect_fail(self, ip_str, sni=None, reason="", force_remove=True):

info = self._get_domain(top_domain)
info["fail_times"] += 1
info["links"] -= 1
self.logger.debug("ip %s sni:%s connect fail, reason:%s", ip, sni, reason)

def update_ip(self, ip_str, sni, handshake_time):
Expand Down
2 changes: 2 additions & 0 deletions code/default/x_tunnel/local/proxy_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ def handle(self):

except socket.error as e:
xlog.debug('socks handler read error %r', e)
self.connection.close()
return
except Exception as e:
xlog.exception("any err:%r", e)
self.connection.close()

def read_null_end_line(self):
sock = self.connection
Expand Down
Loading

0 comments on commit 62862fa

Please sign in to comment.