Skip to content

Conversation

@jason-lynch
Copy link
Member

@jason-lynch jason-lynch commented Jan 29, 2026

Summary

Adds a condition to ignore NotFound errors in PostgresService.Delete, which happens when the service has already been deleted.

Testing

  • Create a database with one node on host-2
  • Remove the host-2 control plane service and the postgres service for the database with docker service rm <name or id>
  • Forcefully remove host-2 with cp-req remove-host --force host-2

Prior to this change, we'd get an error in the last step from trying to scale down a service that no longer exists.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of service deletion operations to gracefully handle cases where a service has already been removed, reducing unnecessary error reporting and enhancing system stability during cleanup operations.

✏️ Tip: You can customize this high-level summary in your review settings.

Adds a condition to ignore NotFound errors in `PostgresService.Delete`,
which happens when the service has already been deleted.
@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

The PostgresService.Delete method in Docker Swarm orchestration now gracefully handles the case where a service is not found during scale-down operations, treating it as already deleted and returning nil instead of propagating the error.

Changes

Cohort / File(s) Summary
Docker Swarm Error Handling
server/internal/orchestrator/swarm/postgres_service.go
Added logic to detect docker.ErrNotFound from scale-down operation and treat it as a successful deletion, returning nil instead of an error. Other errors remain unaffected.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A service not found, oh what a sight,
No need to fret or pick a fight,
Already deleted, the rabbit knows,
Return nil smoothly as the code flows! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: ignoring already-deleted services in the PostgresService.Delete method.
Description check ✅ Passed The description includes Summary and Testing sections as required by the template, though it omits Changes, Checklist, and Notes for Reviewers sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
server/internal/orchestrator/swarm/postgres_service.go (1)

169-171: Handle ErrNotFound on ServiceRemove to avoid race failures.

A concurrent delete between scale-down and remove can surface an error, which breaks the idempotent delete behavior. Docker's ServiceRemove() returns ErrNotFound when the service is already gone; this should be treated as success, mirroring the existing pattern for ServiceScale (line 162–164).

Suggested patch
-	if err := client.ServiceRemove(ctx, s.ServiceName); err != nil {
-		return fmt.Errorf("failed to remove postgres service: %w", err)
-	}
+	if err := client.ServiceRemove(ctx, s.ServiceName); err != nil {
+		if errors.Is(err, docker.ErrNotFound) {
+			return nil
+		}
+		return fmt.Errorf("failed to remove postgres service: %w", err)
+	}

Copy link
Contributor

@rshoemaker rshoemaker left a comment

Choose a reason for hiding this comment

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

lgtm

@jason-lynch jason-lynch merged commit 96623d9 into main Jan 29, 2026
3 checks passed
@jason-lynch jason-lynch deleted the fix/ignore-deleted-service branch January 29, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants