Skip to content

bug: managed_children and the workload launcher mishandle a poisoned lock, a missing CONFIG_PROC_CHILDREN and a panicking job #5186

Open

Description

@EmilienM

User Story

I run OpenShell sandboxes with the Podman and Kubernetes drivers, and I read through the isolation core (openshell-sandbox, openshell-binary-identity, openshell-isolation-interface) at 00528d24a. This item comes from reading the code. I have not hit it in production. It is one line of the umbrella issue #5179.

Problem Statement

  • crates/openshell-sandbox/src/managed_children.rs:97: unregister does if let Ok(mut children) = MANAGED_CHILDREN.lock(), so after a poisoned lock it silently does nothing, while the other accessors recover with into_inner. Registered PIDs then stay "managed" forever, and when one is reused by an adopted orphan the reaper skips it permanently.
  • managed_children.rs:236: direct_child_pids treats NotFound on /proc/self/task/*/children as "task vanished" and continues. On kernels without CONFIG_PROC_CHILDREN every file is missing, so the orphan reaper finds no children and zombies accumulate until pids.max.
  • crates/openshell-sandbox/src/linux/workload_launcher.rs:94: while let Ok(job) = jobs_rx.recv() { job(); } runs jobs without catching panics. A panic inside job() unwinds the thread before thread_alive.store(false, ...) runs, so the launcher keeps reporting healthy while every later spawn fails.

Impact / Why This Matters

Rare but silent failures: leaked registrations, an inert zombie reaper on minimal guest kernels (Kata or microVM configs), and a launcher that reports alive while spawns fail.

Acceptance Criteria

  • unregister recovers from a poisoned lock like its siblings.
  • The reaper detects a missing children file (distinguish from a vanished task, for example by checking /proc/self/task/<tid> first) and logs once.
  • A panicking launcher job is caught, reported, and the launcher health flag reflects it.
  • Tests cover each path.

Reproduction Steps

Found by reading the code; not reproduced live. Panic while holding the managed-children lock in a test, then call unregister; run the sandbox on a kernel without CONFIG_PROC_CHILDREN and orphan a child. Not run yet.

Environment

  • OpenShell: main at 00528d24a
  • OS: Fedora 44, Linux 7.2.14
  • Deployment: Podman driver (local gateway); code read for the Kubernetes driver too

Activity

  1. added
    state:triage-needed
    on Nov 3, 2026
  2. aron-intframe commented on Nov 3, 2026

    @aron-intframe

    I checked all three against main at cc0642f, where the cited lines (managed_children.rs:97 and :236, workload_launcher.rs:94) are still the same code. Each one reproduces. The cause is the same in all three: the failure path falls back to a value that looks normal. unregister treats a poisoned lock as "nothing to remove", direct_child_pids treats a missing children file as "no children", and the launcher's alive flag is only cleared on a normal return, never during unwinding.

    How I checked. I copied register/lock/unregister/is_managed/direct_child_pids from managed_children.rs and start/execute/is_alive from linux/workload_launcher.rs into one std-only file. The logic is unchanged. The only edits: install_workload_listener() is stubbed, since it installs the seccomp filter, and the /proc/self/task root is a parameter. Then I ran rustc --edition 2024 -O repro.rs && ./repro on Linux 6.8:

    rustc 1.99.1 (58cf8f9c3 2026-10-13)
    == 1. unregister() after the registry mutex is poisoned
      [panic hook] panicked at repro.rs:128:49:
    panic while holding the registry guard
      poisoned: true
      current unregister(): is_managed(4242) = true
      later child, unregister(): is_managed(4343) = true   (poison is sticky)
      unregister via lock():  is_managed(4242) = false, is_managed(4343) = false
    == 2. direct_child_pids() when the kernel has no task/<tid>/children
      with children files:     [2085862, 2085863, 2085864]
      without children files:  Ok({})  <- Ok(empty), same as 'no children'
      ppid scan of /proc/*/stat: [2085862, 2085863, 2085864]
    == 3. launcher job panics (current code)
      first job:        Ok(1)
      [panic hook] panicked at repro.rs:161:75:
    job panicked
      panicking job:    Err("workload launcher dropped the spawn result")
      is_alive():       true
      next job:         Err("workload launcher stopped")
    == 3. launcher job panics (with MarkDead drop guard)
      first job:        Ok(1)
      [panic hook] panicked at repro.rs:161:75:
    job panicked
      panicking job:    Err("workload launcher dropped the spawn result")
      is_alive():       false
      next job:         Err("workload launcher is not running")
    

    1. Poisoned lock. One panic while a RegistryGuard is held poisons the mutex for the rest of the process, because std never clears the flag on its own. From then on unregister does nothing for every child, including ones registered later (4343 above), so the registry only grows. Calling lock() inside unregister, as the other accessors already do, fixes it. Today this is latent. The guarded sections I read (process.rs:661, boundary_exec.rs:251 and :361, the reaper) drop the guard before any expect. The one call I found that can panic under the guard is tokio::runtime::Handle::current() in spawn_command_with_workload_launcher (process.rs:441), and it only panics when called off a runtime thread. No workspace profile sets panic = "abort", so release builds can poison too.

    2. Missing children file. I can't boot a CONFIG_PROC_CHILDREN=n kernel here (this host has =y). Instead I gave the same function a task tree with the children files missing, which is what such a kernel exposes: the entry is compiled out, so open() returns ENOENT. The function returns Ok({}), and the reaper can't tell that apart from "no children". A scan of /proc/*/stat for field 4 (ppid) == getpid() found the same three children and needs no kernel option. Splitting after the last ) keeps a comm with spaces from breaking the parse. A possible fallback: in start_orphan_reaper, probe /proc/thread-self/children once. If it's NotFound, log once and use the ppid scan.

    3. Launcher reports healthy after a panic. The panicking call doesn't hang. Its result_tx drops during unwinding, so the caller gets dropped the spawn result. But alive stays true, so measure_confirmation (boundary_server.rs:3811) passes its launcher check while every later execute() fails with workload launcher stopped. A drop guard at the top of the thread closure clears the flag on both a return and an unwind, and it can replace the three manual store(false) calls:

    struct MarkDead(Arc<AtomicBool>);
    impl Drop for MarkDead {
        fn drop(&mut self) { self.0.store(false, Ordering::Release); }
    }
    let _dead_on_exit = MarkDead(thread_alive.clone());

    That is the second launcher run above: is_alive() turns false and the next job gets workload launcher is not running. If you'd rather keep the launcher serving after a bad job, network_broker.rs:313 already wraps dispatch in catch_unwind for the same reason. The same wrap around job() would work, and the failing caller still gets its error because its result_tx is dropped.

    For the tests: (1) can poison with thread::spawn(|| { let _g = lock(); panic!() }).join(). It should run in its own process, the way the existing reaper test re-execs itself, because the poison is global to the test binary. (2) can take the task root as a parameter. (3) is a launcher given one panicking job, followed by assertions on is_alive() and the next execute().

    All three come down to one thing: a failure path that returns something that looks like success. We keep notes on this kind of bug (ours): https://github.com/aron-intframe/agent-guards#1-the-guard-that-prints-nothing

  3. EmilienM commented on Nov 3, 2026

    @EmilienM
    ContributorAuthor

    FYI I have a PR incoming

  4. added
    state:accepted
    on Nov 3, 2026
  5. mrunalp commented on Nov 3, 2026

    @mrunalp
    Contributor

    Accepted for implementation in #5209.

    Source inspection at 32dcc4a67: The registry unregister path skips poisoned locks, missing task children files are treated as vanished tasks, and a panicking launcher job bypasses the normal health-flag reset. These are concrete failure-handling gaps; the report also includes an independent reproducer, which I have not rerun.

    This assessment is based on the source and the linked report/PR; I have not independently run deployment reproductions or the PR test suite. CI and code review still need to validate the fix.

  6. removed
    state:triage-needed
    on Nov 3, 2026
  7. added 2 commits that reference this issue on Nov 4, 2026
    e74a054
    6c769e8
  8. added
    area:runtime
    topic:reliability
    on Nov 15, 2026
  9. added 2 commits that reference this issue on Nov 23, 2026
    8dd36f9
    4c9143d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:runtimestate:acceptedtopic:reliability

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions