Repository navigation
Conversation
…rvisor start A sandbox restart starts the workload before its supervisor. Until the supervisor start returns, the supervisor still reports the exit from the previous run. A watcher inspect in that window treated it as a lost supervisor and stopped the new workload with timeout 0, which moved the sandbox from Starting to Error with ContainerExited. Mark the workload and supervisor start as in progress, and report the workload as starting during that window. A missing supervisor, or an exited one outside a start, is still contained. Supervisor events also re-inspected the workload without the previous-exit fence, so a delayed supervisor stop or die from the last StopSandbox could publish the earlier run's exit. Apply the fence to those snapshots too. Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix an intermittent race in the Podman driver where a sandbox restarted with StopSandbox then StartSandbox moves from
StartingtoErrorwith reasonContainerExited. The watcher killed the freshly started workload because, during the restart, the supervisor still showed the exit from the previous run. A second, related path let a late supervisor event publish the previous run's exit.Related Issue
No issue required: localized bug fix for an intermittent CI failure; the race and evidence are described below.
How the race happens
Each Podman sandbox is a pair of containers: the workload and its supervisor.
start_sandboxstarts them in two separate API calls, workload first:The watcher handles Podman events on its own task. For every workload or supervisor event, it calls
inspect_workload, which inspects the workload and then the supervisor. A running workload whose supervisor is not running is treated as a lost supervisor and contained withstop_container(workload, 0). On first create that check never fires, because the new supervisor is increatedstate, which is reported as starting. On a restart the supervisor is stillexitedfrom the StopSandbox.Race 1: the watcher stops the new workload (the CI failure)
exited.start_container(workload). Podman emits a workloadstartevent.stop/diefrom step 1, beforestart_container(supervisor)takes effect.inspect_workloadsees a running workload and anexitedsupervisor.stop_container(workload, 0). The new workload is killed, and the re-inspect reports itexited.start_container(supervisor)succeeds and StartSandbox returns OK. The gateway receives the snapshot from step 4 and moves the sandboxStarting→ErrorwithContainerExited.This matches the gateway log of the failing run (lane
rust-podman-additional-ca, testattach::attach_reconnect_replays_history_for_the_same_main_process) for sandbox1a1665c3:Whether it happens depends on whether the watcher's inspect lands inside the gap between the two start calls. That's why it is intermittent and why earlier runs of the same lane passed.
Race 2: a late supervisor event publishes the previous exit
Podman can deliver a container's
stop/dieevent after the stop API returned. The existingLifecycleEventFencesalready drops a workloaddie/stopwhose snapshot shows the exit recorded at the last stop or start. Supervisor events went through a separate early branch inmap_podman_eventthat re-inspected the workload without that check. If a supervisor event from StopSandbox is handled after the gateway setStartingbut before the workload start, the snapshot still shows the previous run'sexitedworkload, and the gateway moves the sandbox toErrorthe same way.How this fix resolves it
start_sandboxnow starts the pair throughstart_stopped_pair. It holds a per-sandbox pair-start guard (LifecycleEventFences::begin_pair_start) from beforestart_container(workload)untilstart_container(supervisor)returns, or until the workload is stopped after a failed supervisor start. While that guard is held,inspect_workloadreports a running workload with a not-yet-running supervisor asstartingrather than stopping it. Any inspect inside the gap now publishesStarting, and the next event after the supervisor starts reports the real state.map_podman_eventnow applies the same previous-exit check (is_previous_exit) to its workload snapshot. A workload exit published after a containment has a newFinishedAt, so it still goes through.Changes
watcher.rs: add the pair-start guard toLifecycleEventFences.inspect_workloadtakes the fences and treats an in-progress pair start as starting. Splitmatches_previous_exitinto an action check plusis_previous_exit, and apply the latter to supervisor-triggered snapshots.driver.rs: both restart paths instart_sandbox(recovery and fresh credentials) usestart_stopped_pair.get_sandboxandlist_sandboxespass the shared fences toinspect_workload.Testing
cargo test -p openshell-driver-podmanpassescargo clippy -p openshell-driver-podman --all-targets -- -D warningsis clean; the pre-commitrust:linthook passedwatcher.rs:restarted_workload_is_not_contained_before_supervisor_start: running workload plus an exited supervisor during a pair start reports starting and issues no stop.exited_supervisor_outside_a_start_stops_workload: the same state outside a start, or during another sandbox's start, is still contained.delayed_supervisor_event_does_not_publish_previous_workload_exit: a supervisordiewhose workload snapshot matches the recorded previous exit is dropped.rust-podman*E2E lanes.Checklist