{"record":{"id":"a9f9b0d19c584c0f","repo":"hashicorp/nomad","slug":"volume-q-is-in-use-v","errorCode":null,"errorMessage":"volume %q is in use: %v","messagePattern":"volume %q is in use: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/csi/client.go","lineNumber":508,"sourceCode":"\treturn NewListVolumesResponse(resp), nil\n}\n\nfunc (c *client) ControllerDeleteVolume(ctx context.Context, req *ControllerDeleteVolumeRequest, opts ...grpc.CallOption) error {\n\tif err := c.ensureConnected(ctx); err != nil {\n\t\treturn err\n\t}\n\n\terr := req.Validate()\n\tif err != nil {\n\t\treturn err\n\t}\n\tcreq := req.ToCSIRepresentation()\n\t_, err = c.controllerClient.DeleteVolume(ctx, creq, opts...)\n\tif err != nil {\n\t\tcode := status.Code(err)\n\t\tswitch code {\n\t\tcase codes.FailedPrecondition:\n\t\t\treturn fmt.Errorf(\"volume %q is in use: %v\", req.ExternalVolumeID, err)\n\t\tcase codes.Internal:\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"controller plugin returned an internal error, check the plugin allocation logs for more information: %v\", err)\n\t\t}\n\t}\n\treturn err\n}\n\nfunc (c *client) ControllerExpandVolume(ctx context.Context, req *ControllerExpandVolumeRequest, opts ...grpc.CallOption) (*ControllerExpandVolumeResponse, error) {\n\tif err := req.Validate(); err != nil {\n\t\treturn nil, err\n\t}\n\tif err := c.ensureConnected(ctx); err != nil {\n\t\treturn nil, err\n\t}\n\n\texReq := req.ToCSIRepresentation()\n\tresp, err := c.controllerClient.ControllerExpandVolume(ctx, exReq, opts...)","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/plugins/csi/client.go#L490-L526","documentation":"ControllerDeleteVolume got gRPC code FailedPrecondition from the CSI plugin: the volume req.ExternalVolumeID cannot be deleted because it is still in use — attachments/staged/published state exists on nodes. Nomad wraps it as \"volume is in use\".","triggerScenarios":"Calling ControllerDeleteVolume while the volume is still attached or staged on one or more nodes — the plugin returns codes.FailedPrecondition per the CSI spec. In Nomad this happens when deregistering/deleting a volume that allocations still claim.","commonSituations":"Deleting a volume used by a running job; orphaned node attachments after a node was lost without unstaging; allocations stuck in a pending state holding the claim; forgotten volume claim from a stopped-but-not-GC'd allocation.","solutions":["Stop the jobs/allocations using the volume (`nomad job stop`) and wait for claims to be released.","Run `nomad volume status <id>` to find claimed nodes and wait for unstage/unpublish, or force-release claims with `nomad volume detach` (Nomad >=1.1).","If a node is gone, deregister the node or use `nomad volume detach <vol> <node_id>` to clear the stale attachment.","Retry ControllerDeleteVolume after all claims are cleared."],"exampleFix":"// before (delete while allocations still claim it)\nnomad volume delete <volume_id>\n// after\nnomad job stop <job_using_volume>\nnomad volume detach <volume_id> <node_id>\nnomad volume delete <volume_id>","handlingStrategy":"validation","validationCode":"// Ensure no Nomad claims remain before deleting\nvs, err := client.Volumes().Get(volumeID, nil)\nif err != nil { return err }\nif len(vs.CondensedConstraints) > 0 || len(vs.Reads) > 0 || len(vs.Writes) > 0 {\n    return fmt.Errorf(\"volume %s still has claims; stop consumers first\", volumeID)\n}","typeGuard":null,"tryCatchPattern":"err := client.ControllerDeleteVolume(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"is in use\") {\n    // release claims: stop jobs / nomad volume detach, then retry delete\n}","preventionTips":["Always stop the consuming job before deleting its volumes.","Use `nomad volume status` to confirm zero claims before deletion.","Clean up stale node attachments with `nomad volume detach` when nodes are lost.","Automate volume lifecycle so deletes follow claim release, not precede it."],"tags":["csi","grpc","storage","volume-in-use","cleanup"],"backgroundTag":"volume-still-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"}