Skip to content

daemon: improve Windows service registration cleanup, and make un-registration idempotent - #53845

Merged
thaJeztah merged 3 commits into
moby:masterfrom
thaJeztah:unregister_idempotent
Oct 6, 2026
Merged

thaJeztah merged 3 commits into
moby:masterfrom
thaJeztah:unregister_idempotent

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

daemon: handle Windows event log removal errors

Delete the Windows service before removing its event log source, so a
failure to delete the service does not leave an installed service without
its event log registration.

Also propagate errors from eventlog.Remove instead of silently ignoring
them.

daemon: clean up Windows service after registration failure

Remove the Windows service if registration fails after it was created,
preventing a partially configured service from being left behind.

Keep the original registration error and treat errors encountered while
rolling back or closing the service handle as best-effort cleanup.

daemon: make Windows service unregistration idempotent

Treat an already absent service or one already marked for deletion as a
successful unregister operation.

Continue removing the event log registration in those cases so retries
also clean up stale registration state left by an earlier partial
unregister.

Release notes (optional)

- Improve Windows service registration and unregistration cleanup, including making service unregistration (`--unregister-service`) idempotent.

A picture of a cute animal (not mandatory but encouraged)

Delete the Windows service before removing its event log source, so a
failure to delete the service does not leave an installed service without
its event log registration.

Also propagate errors from eventlog.Remove instead of silently ignoring
them.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Remove the Windows service if registration fails after it was created,
preventing a partially configured service from being left behind.

Keep the original registration error and treat errors encountered while
rolling back or closing the service handle as best-effort cleanup.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Treat an already absent service or one already marked for deletion as a
successful unregister operation.

Continue removing the event log registration in those cases so retries
also clean up stale registration state left by an earlier partial
unregister.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah added this to the 29.9.0 milestone Oct 2, 2026
@thaJeztah thaJeztah added platform/windows status/2-code-review kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. impact/changelog area/daemon Core Engine labels Oct 2, 2026
@thaJeztah
thaJeztah requested a balanced review from Copilot October 3, 2026 08:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The Windows cleanup paths correctly preserve primary errors while safely handling partial or repeated operations.

Review effort: Balanced
Findings: None

What changed in this PR

Improves reliability and idempotency of Windows service registration cleanup.

Changes:

  • Rolls back service creation when registration fails.
  • Deletes services before removing event-log registration.
  • Treats absent services, pending deletion, and missing event-log keys as successful cleanup.
File Description
daemon/​command/​service_windows.go Adds transactional registration cleanup and idempotent unregistration behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@thaJeztah
thaJeztah requested review from corhere and crazy-max October 3, 2026 08:33
@thaJeztah
thaJeztah merged commit 417af1d into moby:master Oct 6, 2026
472 of 502 checks passed
@thaJeztah
thaJeztah deleted the unregister_idempotent branch October 6, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/daemon Core Engine impact/changelog kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. platform/windows status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants