mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
fix(proxy-node): 修复服务重启后 tunnel 连接状态不一致的问题
- 启动时重置 DB 中残留的 tunnel_connected=True 状态 - health_scheduler 以 TunnelManager 内存实际连接为准判断节点状态 - tunnel 模式注册时初始状态设为 UNHEALTHY,等 tunnel 连接后再上线
This commit is contained in:
@@ -53,6 +53,9 @@ class ProxyNodeHealthScheduler:
|
||||
await self._check_heartbeats()
|
||||
|
||||
async def _check_heartbeats(self) -> None:
|
||||
from src.services.proxy_node.tunnel_manager import get_tunnel_manager
|
||||
|
||||
manager = get_tunnel_manager()
|
||||
db = create_session()
|
||||
try:
|
||||
now = datetime.now(timezone.utc)
|
||||
@@ -71,7 +74,20 @@ class ProxyNodeHealthScheduler:
|
||||
|
||||
changed = 0
|
||||
for node in nodes:
|
||||
if node.tunnel_connected:
|
||||
# 以 TunnelManager 内存中的实际连接状态为准,
|
||||
# 而非仅依赖 DB 的 tunnel_connected 字段。
|
||||
# 服务端重启后 DB 可能残留 tunnel_connected=True,
|
||||
# 但 TunnelManager 内存中已无连接。
|
||||
actually_connected = manager.has_tunnel(node.id)
|
||||
|
||||
# 同步修正 DB 中不一致的 tunnel_connected 字段
|
||||
if node.tunnel_connected != actually_connected:
|
||||
node.tunnel_connected = actually_connected
|
||||
if not actually_connected:
|
||||
node.tunnel_connected_at = now
|
||||
changed += 1
|
||||
|
||||
if actually_connected:
|
||||
new_status = ProxyNodeStatus.ONLINE
|
||||
elif node.tunnel_connected_at:
|
||||
# tunnel 刚断开:给 60s 缓冲期标记为 UNHEALTHY
|
||||
|
||||
@@ -210,10 +210,14 @@ class ProxyNodeService:
|
||||
)
|
||||
else:
|
||||
node = db.query(ProxyNode).filter(ProxyNode.ip == ip, ProxyNode.port == port).first()
|
||||
# tunnel 模式注册时设为 UNHEALTHY,等 WebSocket tunnel 真正连接后
|
||||
# 由 _update_tunnel_status 设为 ONLINE;非 tunnel 模式保持原逻辑
|
||||
initial_status = ProxyNodeStatus.UNHEALTHY if tunnel_mode else ProxyNodeStatus.ONLINE
|
||||
|
||||
if node:
|
||||
node.name = name
|
||||
node.region = region
|
||||
node.status = ProxyNodeStatus.ONLINE
|
||||
node.status = initial_status
|
||||
node.last_heartbeat_at = now
|
||||
node.heartbeat_interval = heartbeat_interval
|
||||
node.tunnel_mode = tunnel_mode
|
||||
@@ -234,7 +238,7 @@ class ProxyNodeService:
|
||||
ip=ip,
|
||||
port=port,
|
||||
region=region,
|
||||
status=ProxyNodeStatus.ONLINE,
|
||||
status=initial_status,
|
||||
registered_by=registered_by,
|
||||
last_heartbeat_at=now,
|
||||
heartbeat_interval=heartbeat_interval,
|
||||
|
||||
Reference in New Issue
Block a user