Commit b505e47
committed
fix(natsrouter,testutil): close Add+Wait race; tighten panic-backstop test fidelity; document best-effort cleanup
CodeRabbit review on PR #157 surfaced three items on the squashed
branch:
(MAJOR) pkg/natsrouter/router.go — Shutdown's wg.Wait() phase could
race with Add(1) calls from still-draining subscriptions when the
closeLoop broke early on ctx.Done(). Per sync.WaitGroup docs, Add
concurrent with Wait is undefined when the counter is zero (panic
risk). Fix: track allClosed; only enter the wg.Wait block when every
subscription confirmed close. If ctx expired before all subs closed,
surface the error and let the caller's deadline take precedence --
remaining handler goroutines continue in the background until process
exit. Comment block rewritten to explain the invariant.
(NIT) pkg/natsrouter/integration_test.go — TestIntegration_SpawnSite-
PanicBackstop used WithMaxConcurrency(2). With cap=2, a leaked
semaphore slot would still leave capacity for the follow-up "ok"
request, masking a cleanup regression. Switched to cap=1 so a leaked
slot blocks the second request and the test actually observes slot
release. Added a comment explaining why cap=1 is load-bearing.
(NIT) pkg/testutil/minio.go — replaced two `_ = container.Terminate(ctx)`
calls with explicit "best-effort cleanup" comments per CLAUDE.md
"never ignore errors silently — comment if intentionally discarded".
The discarded errors are intentional (init already failed; Docker
reaps the container on test-process exit either way), now documented.1 parent 3126cd4 commit b505e47
3 files changed
Lines changed: 35 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
285 | 291 | | |
286 | 292 | | |
287 | 293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
263 | 268 | | |
264 | 269 | | |
265 | 270 | | |
266 | 271 | | |
267 | 272 | | |
268 | 273 | | |
| 274 | + | |
269 | 275 | | |
270 | 276 | | |
271 | 277 | | |
272 | 278 | | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
285 | 293 | | |
286 | 294 | | |
287 | 295 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
| |||
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| |||
0 commit comments