Commit 8f5081b
authored
fix: ProxyManager.stop/stop_silent send signal + abort task 保证端口释放 (#207)
silent failure 修: 用户点"停止转发"后 UI/日志显示 "forwarding stopped"
但端口实际仍被占用。
根因: stop_silent (proxy_runner.rs:127) 只 fire-and-forget 发 oneshot
shutdown 信号立刻返, 但 axum::serve.with_graceful_shutdown (start
line 81-87) 收到信号后**等所有 in-flight HTTP connection 完成**才 drop
listener。SSE / long polling / keep-alive idle / hung connection 可能
永远等不到 → listener 不 drop → 端口不释放, 但 UI / log 已"stopped"
→ 用户感知"日志说停了实际没停"。
修法:
- ProxyHandle 加 task: tokio::task::JoinHandle<()> 字段, start 把
tokio::spawn 的 JoinHandle 存进 handle。
- stop / stop_silent 在 shutdown_tx.send(()) **之后**立刻调
h.task.abort() 强制 drop server future → listener 同步 drop →
端口立刻释放, 不依赖 graceful drain。
- race condition path (proxy already started by another path) 同样
abort 自己的 task 防 listener leak。
代价: in-flight HTTP connection 被强断, client 见 connection reset。
但"用户点停止 = 真要停"语义对, 这是合理 trade-off。
测试: 95/95 pass, 无 regression。proxy_runner.rs 现无单测基础设施,
unit test 加 mock config_file 工程量大, 靠 PR 真机测验:
1. 启转发, lsof -iTCP:18080 应看到 axum process
2. 点停止
3. lsof -iTCP:18080 应**立即**空, 无残留
4. 立刻重启转发应成功(端口已释放, bind 不报 Address already in use)1 parent 7e42148 commit 8f5081b
1 file changed
Lines changed: 26 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
40 | 50 | | |
41 | 51 | | |
42 | 52 | | |
| |||
78 | 88 | | |
79 | 89 | | |
80 | 90 | | |
81 | | - | |
| 91 | + | |
82 | 92 | | |
83 | 93 | | |
84 | 94 | | |
| |||
90 | 100 | | |
91 | 101 | | |
92 | 102 | | |
| 103 | + | |
93 | 104 | | |
94 | 105 | | |
95 | 106 | | |
96 | 107 | | |
97 | 108 | | |
98 | 109 | | |
99 | | - | |
| 110 | + | |
| 111 | + | |
100 | 112 | | |
| 113 | + | |
101 | 114 | | |
102 | 115 | | |
103 | 116 | | |
| |||
110 | 123 | | |
111 | 124 | | |
112 | 125 | | |
113 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
114 | 134 | | |
115 | 135 | | |
116 | 136 | | |
117 | 137 | | |
118 | 138 | | |
119 | 139 | | |
| 140 | + | |
120 | 141 | | |
121 | 142 | | |
122 | 143 | | |
123 | 144 | | |
124 | 145 | | |
125 | 146 | | |
126 | 147 | | |
| 148 | + | |
127 | 149 | | |
128 | 150 | | |
129 | 151 | | |
130 | 152 | | |
| 153 | + | |
131 | 154 | | |
132 | 155 | | |
133 | 156 | | |
| |||
0 commit comments