hashicorp/nomad · error
could not delete service - %w
Error message
could not delete service - %w
What it means
performUninstall wraps the error from srvc.Delete(), the final step that marks the Nomad service for removal from the SCM. If the service cannot be deleted, it remains registered and the uninstall fails. The service has already been stopped and its eventlog disabled at this point.
Source
Thrown at command/windows_service_uninstall.go:117
// Grab the service and ensure the service is stopped
srvc, err := m.GetService(winsvc.WINDOWS_SERVICE_NAME)
if err != nil {
return fmt.Errorf("could not get existing service - %w", err)
}
defer srvc.Close()
if err := srvc.Stop(); err != nil {
return fmt.Errorf("unable to stop service - %w", err)
}
// Remove the service from the event log
if err := srvc.DisableEventlog(); err != nil {
return fmt.Errorf("could not remove eventlog configuration - %w", err)
}
// Finally, delete the service
if err := srvc.Delete(); err != nil {
return fmt.Errorf("could not delete service - %w", err)
}
return nil
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Run the uninstall elevated; check the wrapped error code for ERROR_ACCESS_DENIED
- Close other tools holding handles to the service (sc query, service viewers) and retry
- If the service is marked DELETE_PENDING, reboot to complete removal, then verify with `sc query nomad`
- Fall back to `sc delete nomad` manually after fixing permissions
Example fix
# verify and manual fallback sc query nomad sc delete nomad
Defensive patterns
Strategy: retry
Try / catch
err := uninstallCmd.Run()
if err != nil && strings.Contains(err.Error(), "could not delete service") {
// close other SCM handles, then retry once; reboot if DELETE_PENDING
_ = exec.Command("sc", "delete", "nomad").Run()
} Prevention
- Run uninstalls elevated
- Avoid running `sc query`/service viewers concurrently with uninstall
- Verify deletion with `sc query nomad` returning 1060 (not installed)
When it happens
Trigger: srvc.Delete() fails due to lack of DELETE permission on the service (non-elevated run), the service is marked for removal but a handle is still open, or the SCM rejects deletion because the process holds open service handles.
Common situations: Uninstall from non-admin shell; another tool (service viewer, EDR) holding an open handle to the service; service pending deletion after a prior failed uninstall.
Related errors
- unable to check for existing service - %w
- could not get existing service - %w
- unable to stop service - %w
- EventLogger is not supported on this platform
- Windows path expansion not supported on this platform
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/6d11845a8de496f7.
Report an issue: GitHub.