Repository navigation
Description
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 rmduringthv run:thv run --name X --transport stdio osvreturns once the detached proxy is spawned.thv stop X && thv rm Xright after it took 63ms and succeeded. The workload's-internalnetwork appeared 3s later, with no containers attached and no workload listed.- API delete during an edit:
POST /api/v1beta/workloads/{name}/editreturns 200 and then runsupdateSingleWorkloadin the background (stop → delete →SaveState→RunWorkloadDetached). ADELETEthat lands between the delete and the recreate finds nothing to remove and returns. The recreate then builds a new-internalnetwork 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
- Removing a workload can delete the shared toolhive-external network out from under a concurrent create #6078: removal can delete the shared
toolhive-externalnetwork out from under a concurrent create (the reverse direction of the same missing coordination). - Failed workload setup leaves its network and DNS container behind #7045: a workload whose setup fails before its MCP container is created leaves its internal network and
<name>-dnscontainer behind, andthv rmdoesn't remove them (a different trigger with the same symptom). - Fail fast on errored e2e workloads and stop API spec leaks #7042 works around this in the e2e specs by waiting for the workload to settle before removing it.
🤖 Generated with Claude Code
Activity
Let e2e workloads settle before removing them
Settle API workloads before cleanup and tidy specs
Fail fast on errored e2e workloads and stop API spec leaks (#7042)