{"record":{"id":"20b57d1e6215e1ad","repo":"hashicorp/nomad","slug":"volume-s-in-use-by-allocations-v","errorCode":null,"errorMessage":"volume %s in use by allocations: %v","messagePattern":"volume (.+?) in use by allocations: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/host_volume_endpoint.go","lineNumber":704,"sourceCode":"\tsnap, err := v.srv.State().Snapshot()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tns := args.RequestNamespace()\n\tid := args.VolumeID\n\n\tvol, err := snap.HostVolumeByID(nil, ns, id, true)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"could not query host volume: %w\", err)\n\t}\n\tif vol == nil {\n\t\treturn fmt.Errorf(\"no such volume: %s\", id)\n\t}\n\tif len(vol.Allocations) > 0 {\n\t\tallocIDs := helper.ConvertSlice(vol.Allocations,\n\t\t\tfunc(a *structs.AllocListStub) string { return a.ID })\n\t\treturn fmt.Errorf(\"volume %s in use by allocations: %v\", id, allocIDs)\n\t}\n\n\t// serialize client RPC and raft write per volume ID\n\tindex, err := v.serializeCall(vol.ID, \"delete\", func() (uint64, error) {\n\t\tif err := v.deleteVolume(vol); err != nil {\n\t\t\tif structs.IsErrUnknownNode(err) || structs.IsErrNoNodeConn(err) {\n\t\t\t\tif !args.Force {\n\t\t\t\t\treturn 0, fmt.Errorf(\n\t\t\t\t\t\t\"volume cannot be removed from unknown node without force=true\")\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn 0, err\n\t\t\t}\n\t\t}\n\t\t_, idx, err := v.srv.raftApply(structs.HostVolumeDeleteRequestType, args)\n\t\tif err != nil {\n\t\t\tv.logger.Error(\"raft apply failed\", \"error\", err, \"method\", \"delete\")\n\t\t\treturn 0, err","sourceCodeStart":686,"sourceCodeEnd":722,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/host_volume_endpoint.go#L686-L722","documentation":"HostVolume.Delete refuses to remove a volume that still has active allocations: if vol.Allocations is non-empty, it lists the allocation IDs in the error. Deleting would orphan running workloads using the volume, so the server blocks the write until the allocations are stopped.","triggerScenarios":"Calling Delete while jobs still reference the volume and have running/pending allocations — e.g. deleting a volume backing a live service job, or leaked allocations from a killed job that haven't been GC'd.","commonSituations":"Tearing down a volume before stopping the jobs that mount it; failed jobs leaving un-GC'd allocations; users deleting by stale CLI output while a deployment is in progress.","solutions":["Stop the jobs using the volume (`nomad job stop <job>`) and wait for their allocations to finish, then retry the delete.","Run `nomad system gc` to clear stale allocations that block deletion.","Purge stopped jobs (`nomad job stop -purge`) so their allocations are removed and no longer reference the volume."],"exampleFix":"// before\nnomad host volume delete my-vol          # in use by allocs [a1, a2]\n// after\nnomad job stop -purge my-app\nnomad system gc\nnomad host volume delete my-vol","handlingStrategy":"validation","validationCode":"vol, _, err := client.HostVolumes().Info(id, nil, nil)\nif err != nil { return err }\nif len(vol.Allocations) > 0 {\n    return fmt.Errorf(\"volume %s still used by %d allocations; stop jobs first\", id, len(vol.Allocations))\n}","typeGuard":null,"tryCatchPattern":"err := client.HostVolumes().Delete(ns, id, nil)\nif err != nil && strings.Contains(err.Error(), \"in use by allocations\") {\n    // stop owning jobs, wait, GC, then retry\n    stopJobsUsingVolume(id)\n    client.System().GC()\n    err = client.HostVolumes().Delete(ns, id, nil)\n}","preventionTips":["Stop and purge jobs before deleting volumes they mount.","Run `nomad system gc` to clear leaked allocations.","Check volume status for allocations as a pre-delete gate in teardown scripts."],"tags":["nomad","host-volumes","resource-in-use","delete","allocations"],"backgroundTag":"resource-in-use","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}