Commit 9887858
fix(cri): tear down the sandbox VM if RunPodSandbox is cancelled before storing it (#116)
RunPodSandbox boots the sandbox VM (acquire_vm_with_box_id) and allocates a
network IP BEFORE it registers the sandbox in the store + vm_managers. The
explicit error paths already clean up, but an async CANCELLATION — the kubelet's
RunPodSandbox deadline drops the gRPC future — between the boot and add_sandbox
left the booted shim microVM and its IP orphaned: VmManager has no Drop, and an
unregistered sandbox is invisible to the reaper, so nothing ever reaped it.
Insert the VM into vm_managers immediately after boot, then arm a CancelGuard
whose Drop (on unwind) disconnects the network synchronously and spawns the
async VM destroy on the still-running runtime. It is disarmed the instant the
sandbox is stored — with no `.await` between add_sandbox and disarm, so a
successfully-created sandbox can never be torn down by a late cancellation.
Test (neuter-verified): test_cancel_guard_runs_cleanup_unless_disarmed — an
armed guard runs its cleanup on drop, a disarmed one does not. Making disarm a
no-op fails the "disarmed guard must not run its cleanup" assertion.
Audit finding #21.
Co-authored-by: Roy Lin <roylin@a3s.box>1 parent fd7b938 commit 9887858
2 files changed
Lines changed: 107 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
75 | 107 | | |
76 | 108 | | |
77 | 109 | | |
| |||
566 | 598 | | |
567 | 599 | | |
568 | 600 | | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
569 | 636 | | |
570 | 637 | | |
571 | 638 | | |
| |||
609 | 676 | | |
610 | 677 | | |
611 | 678 | | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
616 | 684 | | |
617 | 685 | | |
618 | 686 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
47 | 82 | | |
48 | 83 | | |
49 | 84 | | |
| |||
0 commit comments