Commit 0e4ed61
fix(pool): close warm-pool shutdown-vs-replenish push race (orphaned-VM leak) (#145)
From the concurrency audit. A freshly-booted warm VM could be pushed into the
idle pool AFTER drain_idle already cleared it, leaking the VM (mount/IP/volume)
since there is no Drop reaper.
The replenish task checked `*shutdown_rx.borrow()` and only THEN acquired the
idle lock to push — with an await in between. drain_all does signal_shutdown()
then drain_idle() (which locks idle, drains, and runs exactly once). If the
unlocked check observed shutdown=false and drain_idle completed before the task
acquired the lock, the VM was pushed into the already-drained pool and never
reclaimed.
Fix: acquire the idle lock FIRST, then re-check shutdown UNDER it before pushing
— making the check-and-push atomic against drain_idle (which holds the same lock
while draining, always after signal_shutdown). On shutdown, destroy the VM
instead of pushing. The same latent leak existed in `release()` (returns a VM to
the pool with no shutdown check); guard it the same way.
Validated: full a3s-box-runtime pool/lib suite (55) green, fmt + clippy clean.
A minimal check-under-lock change; the interleaving itself needs a real-VM
harness to exercise (like the kill-identity / durable-write fixes).
Co-authored-by: Roy Lin <roylin@a3s.box>1 parent 8afe462 commit 0e4ed61
1 file changed
Lines changed: 19 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
262 | 273 | | |
263 | 274 | | |
264 | 275 | | |
| |||
809 | 820 | | |
810 | 821 | | |
811 | 822 | | |
812 | | - | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
813 | 830 | | |
| 831 | + | |
814 | 832 | | |
815 | 833 | | |
816 | 834 | | |
817 | 835 | | |
818 | 836 | | |
819 | 837 | | |
820 | 838 | | |
821 | | - | |
822 | 839 | | |
823 | 840 | | |
824 | 841 | | |
| |||
0 commit comments