This repository was archived by the owner on Apr 27, 2026. It is now read-only.
Commit 91810da
authored
fix(test): synchronize testHangServer handler goroutines to prevent race (#105)
Use sync.WaitGroup to track active HTTP handler goroutines and wait for
all of them to fully exit before closing reqsCh in t.Cleanup. Previously,
cleanup closed reqsCh (to unblock waiting tests) before all handlers had
exited, creating a data race between a handler sending to reqsCh and the
cleanup goroutine closing it.
The cleanup order is now:
1. close(cleanupCh) — signal handlers to stop
2. server.CloseClientConnections() — force clients to disconnect
3. server.Close() — stop accepting new requests
4. wg.Wait() — wait for all handlers to exit
5. close(reqsCh) — safe to close now1 parent 6e70b94 commit 91810da
1 file changed
Lines changed: 16 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
1135 | 1136 | | |
1136 | 1137 | | |
1137 | 1138 | | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
1143 | 1144 | | |
1144 | 1145 | | |
1145 | 1146 | | |
| |||
1231 | 1232 | | |
1232 | 1233 | | |
1233 | 1234 | | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
1234 | 1240 | | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
1235 | 1244 | | |
1236 | 1245 | | |
1237 | 1246 | | |
| |||
1262 | 1271 | | |
1263 | 1272 | | |
1264 | 1273 | | |
1265 | | - | |
1266 | 1274 | | |
1267 | 1275 | | |
| 1276 | + | |
| 1277 | + | |
1268 | 1278 | | |
1269 | 1279 | | |
1270 | 1280 | | |
0 commit comments