mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-24 06:48:14 +00:00
feat(runtime): hot reload ACL rules with signals
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
**Status**: accepted; system-proxy rollback clause superseded by ADR-0019. Runtime and mode rollback remain.
|
||||
|
||||
**ACL reload superseded (2026-10-20)**: [ADR-0048](0048-reload-sslocal-acl-by-signal.md) replaces restart-on-ACL-change with `SIGUSR2` reload. Listener and authentication changes still require restart.
|
||||
|
||||
## Context
|
||||
|
||||
Global mode previously projected only the system SOCKS endpoint and relied on sslocal's default proxy-everything behaviour. That left local-network targets without a product-owned direct guarantee: LAN-sharing clients, IPv6 destinations whose system-proxy exceptions macOS does not reliably honour, and any request that reaches the SOCKS/HTTP inbounds still needed a defined routing policy. The ACL work (spec #59) requires global mode to mean "public targets default through Shadowsocks, local targets stay direct", using only the fixed local safety rules.
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
**Supersedes in part**: ADR-0009 and ADR-0010's "ACL path, content, digest, and summary are runtime identity" — content is no longer carried in the contract, and the ACL path is a stable link that does not change across mode switches. The restart-on-change rule itself stands.
|
||||
|
||||
**ACL reload superseded (2026-10-20)**: [ADR-0048](0048-reload-sslocal-acl-by-signal.md) replaces restart-on-ACL-change with `SIGUSR2` reload. Listener and authentication changes still require restart.
|
||||
|
||||
## Context
|
||||
|
||||
sslocal's routing policy is one of four ACL shapes — `direct`, `global`, `rule-proxy-default`, `rule-direct-default` — but all four were written into a single `sslocal-active.acl`, overwritten on every proxy mode switch and on every deploy even when the ACL body had not changed. The contract JSON also embedded the full ACL body (`x_shadowsocksx_ng_acl.content`), so a rule-mode switch paid roughly the same large write twice. Upstream sslocal is gaining signal-triggered ACL reload; mode switches should be cheap now and restart-free later.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
**Status**:accepted(2026-10-19)。已实施;验证结果见对应实现提交。
|
||||
|
||||
后续修订:GUI 与上游配置的单向输出及私有意图比较见 [ADR-0043](0043-one-way-sslocal-configuration-output.md)。
|
||||
后续修订:GUI 与上游配置的单向输出及私有意图比较见 [ADR-0043](0043-one-way-sslocal-configuration-output.md)。ACL 变化改用信号热重载见 [ADR-0048](0048-reload-sslocal-acl-by-signal.md),取代下文 ACL 变化必须重启的规定。
|
||||
|
||||
## 职责
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# 通过信号热重载 sslocal ACL
|
||||
|
||||
**状态**:已接受并实施(2026-10-20)。
|
||||
|
||||
使用已固定的 sslocal fork v1.26.0 的 `SIGUSR2` 能力,让规则修改、规则默认动作变化,以及规则/全局/直连模式切换产生的 ACL 更新在原子切换稳定 ACL 链接后热重载,减少子进程重启造成的中断。GUI 继续向 Agent 发送 `SIGUSR1` 通知新部署,Agent 根据变化向 sslocal 发送相应信号。监听、IPv6 监听设置或认证变化仍按原协议停止旧子进程、确认退出后重新启动。
|
||||
|
||||
监管资料通过随机 `configurationID` 表示 sslocal 配置字节的身份,GUI 在旧配置字节及其私有完整性摘要均与本次输出一致时复用该身份。Agent 只比较身份,配置变化时发送 `SIGUSR1`,ACL 变化时发送 `SIGUSR2`;仅切换代理模式或更新 ACL 不重载服务器配置。身份不包含服务器或凭据摘要,Agent 仍不读取秘密配置。第 2 版监管资料允许缺失此字段,遇到旧资料时保守发送 `SIGUSR1`。服务器与 ACL 同时变化时分别发送 `SIGUSR1` 和 `SIGUSR2`,接受两者先后生效的短暂窗口,不为组合变化单独重启,也不承诺原子应用。上游 `SIGUSR1` 仅刷新服务器,不能代替 ACL 重载。
|
||||
|
||||
Agent 对已经健康、无需重启的同一子进程沿用已建立的监听事实,不在热重载前后重复连接端口,也不因信号重载将其降为未就绪。首次启动或重启仍验证新子进程的监听归属。启动监听尚未就绪时合并保留待发信号,监听就绪后发送,防止后续仅服务器更新覆盖之前待发的 ACL 更新。正式 Agent 部署在所有代理模式下始终生成 ACL,不为模型允许的 ACL 空值增加产品转换场景。
|
||||
|
||||
GUI 以仅保存在内存中的非 ACL 意图摘要识别纯 ACL 更新;前提是已处于健康运行态、Agent 已注册、wrapper 与当前回执对应的子进程仍存活。更新期间保持运行状态,不呈现“正在启动代理”,等待当前部署回执但不重复探测未变监听。回执对应子进程 PID 变化时恢复启动状态与完整端口检查;缺少回执、持久失败或进程消失仍报告失败。后台健康轮询避开正在执行的热重载,周期性健康检查在更新完成后继续运行。
|
||||
|
||||
沿用现有回执的证据范围:它只记录 Agent 操作及监听证据,不代表 sslocal 已确认应用新规则。上游在 ACL 读取或解析失败时保留旧规则并记录日志;信号发送成功不能排除这种情况。本次接受此限制,不增加上游应用确认协议或根据日志推断部署成功。链接切换、信号投递或监听检查等可检测的失败继续遵循 ADR-0037,停止服务、暂停系统代理并保留最新意图,不自动恢复旧部署。
|
||||
|
||||
本决定部分替代 ADR-0010、ADR-0011、ADR-0038 中 ACL 变化要求重启的规定;稳定链接的 Agent 独占切换、不可变文件、代次与锁、子进程引用的保守保留及失败屏障继续适用。当前实现仍以代码为准。
|
||||
|
||||
上游依据:[信号处理](https://github.com/qiuyuzhou/shadowsocks-rust/blob/v1.26.0/src/service/local.rs#L1078-L1165)、[ACL 重新加载及原子替换](https://github.com/qiuyuzhou/shadowsocks-rust/blob/v1.26.0/crates/shadowsocks-service/src/acl/mod.rs#L687-L738)。
|
||||
|
||||
验证通过:1150 项 hostless 测试、19 项真实进程 smoke、Lint 与 Debug 构建。定向覆盖模式切换保持运行状态且不重复探测端口、回执缺失与子进程替换、连续模式切换、配置身份复用与旧监管资料保守重载、Agent 热重载前后实际 TCP 连接计数不增加、启动期间待发信号合并、组合服务器与 ACL 更新、规则增删与默认动作变化、模式切换时子进程 PID 保持不变且实际路由变化,以及上游 ACL 解析失败保留旧规则的回执边界。未执行原生界面与真实系统代理验收。
|
||||
Reference in New Issue
Block a user