{"record":{"id":"ec687804bce079fd","repo":"cilium/cilium","slug":"deleteipamipfailurecode","errorCode":"DeleteIpamIPFailureCode","errorMessage":"IP is in use by endpoint %d","messagePattern":"IP is in use by endpoint (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"pkg/ipam/api/ipam_api_handler.go","lineNumber":141,"sourceCode":"\n\treturn nodeRouterAddressing, nil\n}\n\n// Handle incoming address allocation requests for the daemon.\nfunc (r *IpamPostIpamIPHandler) Handle(params ipamapi.PostIpamIPParams) middleware.Responder {\n\towner := swag.StringValue(params.Owner)\n\tpool := ipam.Pool(swag.StringValue(params.Pool))\n\tif err := r.IPAM.AllocateIPString(params.IP, owner, pool); err != nil {\n\t\treturn api.Error(ipamapi.PostIpamIPFailureCode, err)\n\t}\n\n\treturn ipamapi.NewPostIpamIPOK()\n}\n\nfunc (r *IpamDeleteIpamIPHandler) Handle(params ipamapi.DeleteIpamIPParams) middleware.Responder {\n\t// Release of an IP that is in use is not allowed\n\tif ep := r.EndpointManager.LookupIPv4(params.IP); ep != nil {\n\t\treturn api.Error(ipamapi.DeleteIpamIPFailureCode, fmt.Errorf(\"IP is in use by endpoint %d\", ep.ID))\n\t}\n\tif ep := r.EndpointManager.LookupIPv6(params.IP); ep != nil {\n\t\treturn api.Error(ipamapi.DeleteIpamIPFailureCode, fmt.Errorf(\"IP is in use by endpoint %d\", ep.ID))\n\t}\n\n\tip, err := netip.ParseAddr(params.IP)\n\tif err != nil {\n\t\treturn api.Error(ipamapi.DeleteIpamIPInvalidCode, fmt.Errorf(\"Invalid IP address %s: %w\", params.IP, err))\n\t}\n\n\tpool := ipam.Pool(swag.StringValue(params.Pool))\n\tif err := r.IPAM.ReleaseIP(ip, pool); err != nil {\n\t\treturn api.Error(ipamapi.DeleteIpamIPFailureCode, err)\n\t}\n\n\treturn ipamapi.NewDeleteIpamIPOK()\n}\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/pkg/ipam/api/ipam_api_handler.go#L123-L159","documentation":"The DELETE /ipam/IP handler refuses to release an IP currently assigned to an endpoint. It checks EndpointManager.LookupIPv4/LookupIPv6 first and returns a DeleteIpamIPFailureCode API error naming the owning endpoint ID.","triggerScenarios":"DELETE /ipam/IP for an IP bound to a running pod/endpoint; operators cleaning up 'stale' IPs that are actually in use; releasing an IP while its endpoint is terminating but not yet removed.","commonSituations":"Manual cleanup scripts freeing pod CIDR IPs that collide with live workloads; buggy controllers double-releasing IPs; CNI DELETE racing endpoint teardown.","solutions":["Release the IP only after the owning endpoint is deleted (delete the pod or wait for termination to complete)","Verify the endpoint ID in the error and confirm whether it is truly stale; remove the endpoint via the API if it is orphaned","Find a different free IP if you only need a replacement address"],"exampleFix":"// before\ncurl -X DELETE .../ipam/IP?ip=10.0.1.5  # fails: in use by endpoint 1234\n// after\n# 1) remove/confirm the endpoint is gone\nkubectl delete pod my-pod   # or wait for its CNI DELETE to complete\n# 2) then release the IP\ncurl -X DELETE .../ipam/IP?ip=10.0.1.5","handlingStrategy":"try-catch","validationCode":"// Client-side check before DELETE (approximate):\n// list endpoints and ensure none uses the IP\nfunc ipInUse(eps []EndpointInfo, ip string) bool {\n    for _, e := range eps {\n        if e.IPv4 == ip || e.IPv6 == ip { return true }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"resp, err := client.DeleteIpamIP(ip)\nif err != nil && strings.Contains(err.Error(), \"IP is in use by endpoint\") {\n    return skipOrDeleteEndpointFirst(ip) // parse endpoint ID from message\n}\nreturn err","preventionTips":["Release IPs only through the normal CNI/endpoint teardown flow","Check endpoint listings before manual IP cleanup","Handle the 'in use' response as expected behavior, not a bug"],"tags":["ipam","api","endpoint","ip-in-use","go","cilium"],"backgroundTag":"ip-in-use-by-endpoint","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}