Skip to content

Removing a starting or updating workload leaks its Docker network #7043

Open

Description

@tgrunnagle

Summary

Removing a workload while its detached start, or a background update, is still running returns at once and leaves the start running. The start then creates the workload's Docker resources (its toolhive-<name>-internal network, at least) after the removal, and nothing deletes them. Each leaked network uses one of Docker's address pools (about 31 by default), so enough of them make every later workload fail with failed to create internal network: ... all predefined address pools have been fully subnetted.

Observed

Found while tracking network leaks in the e2e suite (#7042):

  • thv rm during thv run: thv run --name X --transport stdio osv returns once the detached proxy is spawned. thv stop X && thv rm X right after it took 63ms and succeeded. The workload's -internal network appeared 3s later, with no containers attached and no workload listed.
  • API delete during an edit: POST /api/v1beta/workloads/{name}/edit returns 200 and then runs updateSingleWorkload in the background (stop → delete → SaveState → RunWorkloadDetached). A DELETE that lands between the delete and the recreate finds nothing to remove and returns. The recreate then builds a new -internal network for a workload that no longer exists.

Likely cause

deleteWorkload → deleteContainerWorkload works from what exists now: the run config, the container from getWorkloadContainer, and the tracked proxy PID. A start that has not created its container yet, or an update between its delete and its recreate, has nothing for it to find. Nothing makes the in-flight start notice the removal and stop (no cancellation, lock, or "removing" check before each resource is created).

Expected

After thv rm (or DELETE /api/v1beta/workloads/{name}) returns successfully, no resources for that workload are created later. Either removal waits for or cancels the in-flight start/update, or the start checks for removal before creating each resource and cleans up what it has created.

Related

🤖 Generated with Claude Code

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions