fix: 修复暗色主题UI对比度、端口占用死循环及多项Web表单bug
后端修复: - engine/instances.py: Socks5Server.start() 端口占用时死循环, 增加超时和异常透传 - engine/instances.py: import time 移至顶层 - engine/instances.py: sync_instances/start_instance 容忍单实例启动失败 - run.py: 启动时 sync_instances 失败不退出进程 - web/routes.py: instances start/restart/edit 路由捕获 OSError, flash 友好提示 - api/v1.py: instances start/restart/update API 返回 JSON 错误而非 500 崩溃 - web/routes.py: toggle_user/ban_user 支持 hidden 字段语义, 缺字段时切换状态 - web/routes.py: inject_nav 增加独立 nav.dashboard 和 page_name, 修复双 active bug - auth.py: login 路由添加 logging import, 修 NameError 前端重构: - templates/base.html: 全局对比度提升(--text #f1f5f9, --accent #a5b4fc), 标题色显式声明, alert/modal/progress/table 完整暗色样式 - templates/base.html: main-content padding-top 修复 navbar 遮挡内容 - templates/base.html: 侧边栏 active 高亮 (白字 + elevated bg + 左边框) - templates/base.html: 顶栏动态显示当前页面名 - templates/*.html: 统一 page-header 类, 所有图标按钮添加 title tooltip - templates/users.html: toggle/ban 表单添加 hidden enabled/ban 字段 - templates/connections.html: fmtBytes 改为 Jinja macro, 时间格式化 - templates/dashboard.html: 时间格式化为 YYYY-MM-DD HH:MM:SS, chart canvas 高度调整 - templates/logs.html: 时间格式化为可读格式 - templates/stats.html: 提升 chart 颜色对比度 - templates/system.html: 使用 time.localtime() 显示本地时间
This commit is contained in:
+42
-8
@@ -2,6 +2,7 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import threading
|
||||
import time
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from engine.server import ConnectionHandler
|
||||
@@ -51,20 +52,41 @@ class Socks5Server:
|
||||
|
||||
self._active_connections = 0
|
||||
self.running = True
|
||||
self.server = None
|
||||
self._start_error = None # 用于在主线程透传子线程异常
|
||||
|
||||
def run_loop():
|
||||
asyncio.set_event_loop(self.loop)
|
||||
self.server = self.loop.run_until_complete(
|
||||
self._create_server()
|
||||
)
|
||||
self.loop.run_forever()
|
||||
try:
|
||||
self.server = self.loop.run_until_complete(
|
||||
self._create_server()
|
||||
)
|
||||
self.loop.run_forever()
|
||||
except Exception as e:
|
||||
# 端口占用等异常:保存异常并停止循环,避免主线程死等
|
||||
self._start_error = e
|
||||
log.error("[%s] SOCKS5 服务器启动失败: %s",
|
||||
self.config.name, e)
|
||||
try:
|
||||
self.loop.stop()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self.thread = threading.Thread(target=run_loop, daemon=True,
|
||||
name=f"socks5-{self.config.name}")
|
||||
self.thread.start()
|
||||
# 等 server 创建完成
|
||||
while self.server is None and self.running:
|
||||
# 等 server 创建完成 (或失败) — 设了上限避免永久死等
|
||||
deadline = time.time() + 5.0
|
||||
while self.server is None and self.running and self._start_error is None:
|
||||
time.sleep(0.05)
|
||||
if time.time() > deadline:
|
||||
log.error("[%s] SOCKS5 服务器启动超时", self.config.name)
|
||||
self.running = False
|
||||
break
|
||||
# 如果子线程失败, 把异常抛回调用方
|
||||
if self._start_error is not None:
|
||||
self.running = False
|
||||
raise self._start_error
|
||||
if self.server:
|
||||
log.info("[%s] SOCKS5 服务器已启动: %s:%d",
|
||||
self.config.name, self.config.listen_host, self.config.listen_port)
|
||||
@@ -157,7 +179,11 @@ class InstanceManager:
|
||||
for name in current_names - running_names:
|
||||
cfg = self._config_cache[name]
|
||||
srv = Socks5Server(cfg, self.user_service, self.flask_app)
|
||||
srv.start()
|
||||
try:
|
||||
srv.start()
|
||||
except OSError as e:
|
||||
log.error("[%s] 跳过启动(端口冲突?): %s", name, e)
|
||||
continue
|
||||
with self._lock:
|
||||
self._instances[name] = srv
|
||||
|
||||
@@ -198,7 +224,15 @@ class InstanceManager:
|
||||
)
|
||||
self._config_cache[inst.name] = cfg
|
||||
srv = Socks5Server(cfg, self.user_service, self.flask_app)
|
||||
srv.start()
|
||||
try:
|
||||
srv.start()
|
||||
except OSError as e:
|
||||
# 端口占用等启动失败: 回滚状态, 清理缓存, 返回 False
|
||||
log.error("[%s] 启动实例失败: %s", inst.name, e)
|
||||
self._config_cache.pop(inst.name, None)
|
||||
inst.running = False
|
||||
db.session.commit()
|
||||
raise
|
||||
with self._lock:
|
||||
self._instances[inst.name] = srv
|
||||
inst.running = True
|
||||
|
||||
Reference in New Issue
Block a user