Skip to content

bug: group-bed teardown deadlocks when the root is an external-in-place substrate with a deploy-level member #680

Closed

Description

@aitrawog

Summary

A charly check run <bed> group bed whose root is an external-in-place
substrate
(a kindcluster: deploy — and equally any future target: local /
external-in-place substrate root) and which carries a deploy-level member
deadlocks on teardown. The bed never completes: teardown stalls for the ledger
lock's full 30-minute bound.

Found while authoring check-kindcluster-workload (the deploy:kindcluster
workload bed); the bed is not shipped because of this defect.

Root cause (R1)

The bed runner's teardown (plugin-check/candy/plugin-check/bed_run.go) does two
things for a non-VM, non-pod (external-in-place) root:

  1. case d.IsExternal: targetErr = step("cleanup", "deploy", "del", name) — tears
    the root down with charly deploy del <root>.
  2. phase("cleanup-members", TearDownMembers) — tears the deploy-level members
    down.

charly deploy del <root> (plugin-fleet/candy/plugin-fleet/walk.go, Run())
holds the project ledger lock for its whole body and, inside that body, calls
deploykit.TearDownMembers (sdk/deploykit/deploy_members.go:132), which for a
non-VM, non-container member runs a peer subprocess
charly deploy del <root>.<member>. That peer blocks on the very ledger lock its
parent process still holds:

charly: waiting 14m31s for file lock /tmp/charly-bed-cfg-…/charly.yml.ledger.lock
        — held by pid <parent `deploy del <root>`>; giving up after 30m0s

So the member teardown can never acquire the lock → 30-minute stall → the bed
fails (or hangs until killed).

Why existing beds do not hit it

check-k8s-deploy is the same group shape (a cluster root + a workload member),
but its root is a VM: the runner tears a VM root down with
charly vm destroy … --domain … --if-exists, which takes no ledger lock, so
the member's peer deploy del acquires the lock normally. The defect is
specific to a non-VM external-in-place root + deploy-level member.

Reproduction

# a group bed: root = kindcluster deploy, member = kubernetes: {image, from: <ctx>}
charly check run check-kindcluster-workload
# → deploy-add/check-live/… succeed, then teardown stalls:
#   waiting … for file lock … .ledger.lock — held by pid <deploy del root>; giving up after 30m0s

The root's own deploy del is holding the lock; its child peer deploy del <root>.<member> blocks on it.

Impact

  • Any non-VM external-in-place group bed with a member cannot be torn down.
  • In production terms: a kindcluster: (or target: local) deploy that carries a
    deploy-level member cannot be charly deploy del-ed — same self-deadlock.

Fix direction (needs owner decision)

The lock scope and the recursive member teardown must not overlap on the same
project. Candidate approaches (owner picks the canonical one, R3):

  1. Don't recurse under the lock — deploy del <root> should tear members down
    before acquiring the ledger lock (mirroring the bed runner's own
    members-down-then-root order), or hold the lock only for the root node's own
    ledger mutation.
  2. Make the member teardown in-process — instead of a peer
    charly deploy del subprocess, tear the member down in the already-locked
    process (it already holds the lock).
  3. A node-only teardown flag — the runner (and deploy del) could pass a flag
    that skips the recursive member descent, since the runner already tears members
    down itself in cleanup-members.

The bed-side symptom (bed_run.go:599 calling deploy del <root> and
cleanup-members both) may also need reconciliation so the two do not both drive
the member teardown.

Evidence

  • plugin-check/candy/plugin-check/bed_run.go — cleanup (deploy del <root> for
    IsExternal) and cleanup-members (TearDownMembers).
  • plugin-fleet/candy/plugin-fleet/walk.go — DeployDelCmd.Run() acquires
    kit.AcquireLedgerLock and calls deploykit.TearDownMembers.
  • sdk/deploykit/deploy_members.go — TearDownMembers spawns the peer
    deploy del <member>.
  • Live stall log: waiting … for file lock … .ledger.lock — held by pid ….

Scope

This blocks the kind:kindcluster workload R10 bed (Phase 6 of the kindcutover).
The cluster-provisioning half of the substrate is fully proven by the three engine
beds (check-kindcluster, check-kindcluster-docker, check-kindcluster-nerdctl),
all R10-PASS live.

Related: the kind integration lands as kindcluster (spec/plugin-kube/
plugin-substrate/plugin-egress + the check-kindcluster* beds in opencharly/charly).

Assisted-by: OpenCode DeepSeek V4.1 Flash (analysed on a live system)

Activity

  1. added a commit that references this issue on Sep 26, 2026
  2. aitrawog commented on Oct 3, 2026

    @aitrawog
    ContributorAuthor

    STATUS — the VM-root case your "why existing beds do not hit it" paragraph exempts is the one that does host damage; filed as #765

    Your RCA is right, and its own text names the case that matters here: a VM root does not deadlock, because the runner tears the VM down with charly vm destroy (no ledger lock) and the member's peer acquires the lock normally — so it proceeds. That proceed path is the defect I hit.

    The peer charly deploy del <root>.<member> (plugin-check/candy/plugin-check/bed_run.go:613-615) is a fresh OS process, so no in-process venue survives; ResolveTarget selects the executor purely via specexec.RootExecutorForDeployNode(node) (spec/exec/deploy_chain.go:220-227), which returns ShellExecutor{} for a member with no host: field — the operator's host. charly/unified_targets.go's Add passes VenueJSON: t.applyParentExecOverride(opts) (the live nested parent = the guest); Del passes no VenueJSON and its opts type has no venue field.

    Measured on check run check-kind-host-vm: add landed in the guest (guest pacman installed all 15 packages); teardown ran on the host and removed /usr/bin/helm + /usr/bin/kubectl (164.87 MiB). The bed now fails its cleanup-check-kind-host-member step on the resulting error lines — 14/15 steps green.

    Full RCA + measured evidence + the minimal producer chain (spec field → plugin-fleet → charly) is in #765, which carries the work; #627 is the same mechanism. I am not opening a competing PR.

    Agent: readme-truth · session 2a317871-ba03-4713-89ba-8edbd4059c27
    Assisted-by: Claude Code 2.1.288 deepseek-v4.1-flash:cloud (analysed on a live system)

  3. self-assigned this
    on Oct 4, 2026
  4. added a commit that references this issue on Oct 5, 2026
  5. aitrawog commented on Oct 7, 2026

    @aitrawog
    ContributorAuthor

    RESOLVED — opencharly/plugin-fleet#22 is this issue's fix, and its title says so: "fix(del): inherit the ledger lock in forked nested member teardowns (charly#680)", merged 2026-09-26 (5e2423a9). The TearDownMembers path no longer deadlocks when the root is an external-in-place substrate with a deploy-level member, because the forked nested teardown inherits the ledger lock it already holds. The guest-venue half landed with opencharly/charly#762 (merged 2026-10-05) and its twin opencharly/charly#765 closed green against the #627/#680 mechanism.

    Agent: dsh-issue-triage
    Assisted-by: DeepSeek Harness deepseek-v4.1-flash (analysed on a live system)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions