Skip to content

fix: improve pihole sessions cleanup#57

Merged
DeepSpace2 merged 1 commit into
masterfrom
fix-pihole-sessions-cleanup-on-errors
Jul 7, 2026
Merged

fix: improve pihole sessions cleanup#57
DeepSpace2 merged 1 commit into
masterfrom
fix-pihole-sessions-cleanup-on-errors

Conversation

@DeepSpace2

@DeepSpace2 DeepSpace2 commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • Improved client setup reliability by returning clearer errors during initialization.
    • Fixed a case where a failed request could incorrectly return no error.
    • Added extra debug logging during Pi-hole logout to make session cleanup easier to trace.

@DeepSpace2 DeepSpace2 added the fix Something isn't working label Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@DeepSpace2, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 49 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2ef01c9c-b3a2-4b67-80b3-7ba3cc09b874

📥 Commits

Reviewing files that changed from the base of the PR and between 5309e1a and 8913260.

📒 Files selected for processing (3)
  • pkg/clients/clients.go
  • pkg/clients/common/common.go
  • pkg/clients/pihole/pihole.go

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.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
putComment timed out

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
pkg/clients/pihole/pihole.go (1)

75-79: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Debug log claims success even on a failed logout response.

Line 76 logs "Logged out from Pi-Hole" unconditionally, right before the Warn on Line 78 for statusCode >= 400. Reading the two logs together is contradictory and undercuts the value of the new debug logging for troubleshooting cleanup failures.

🪵 Suggested reorder
 	p.sid = ""
-	log.Debug("Logged out from Pi-Hole")
 	if statusCode >= 400 {
 		log.Warn("Pi-Hole logout returned non-success status", "status", statusCode)
+	} else {
+		log.Debug("Logged out from Pi-Hole")
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/clients/pihole/pihole.go` around lines 75 - 79, The logout flow in
pihole.go logs “Logged out from Pi-Hole” unconditionally even when Logout
returns a failure status, which makes the debug output misleading. In the Logout
method, gate the success debug log on a non-error statusCode or move it into the
success path so it only prints when the logout actually succeeds; keep the
existing warning for statusCode >= 400 and use the Logout and log.Debug/log.Warn
calls to place the messages correctly.
pkg/clients/clients.go (1)

22-37: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Correct, but the shadow at Line 29 is a subtle gotcha—worth a comment.

Without piholeClient := piholeClient, the deferred closure would reference the named return directly; a later return nil, nil, nil, nil, err (Line 47) zeroes that named variable before the deferred call executes, causing a nil-pointer panic on piholeClient.Logout(). The shadow correctly avoids this, but it's easy for a future edit to remove it without realizing why it's there.

💡 Suggested clarifying comment
-			piholeClient := piholeClient
+			// Capture the client now: subsequent early `return nil, ...` statements
+			// zero the named return `piholeClient`, which would make this deferred
+			// closure panic on a nil pointer if it referenced the named return directly.
+			piholeClient := piholeClient
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/clients/clients.go` around lines 22 - 37, The piholeClient shadow inside
the Login/defer block is intentional but easy to remove accidentally, so add a
clarifying comment near the piholeClient := piholeClient assignment in
clients.go. Make it explicit that the local copy is needed because the deferred
Logout closure must not reference the named return variable, which gets zeroed
on the early return path before defer runs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/clients/clients.go`:
- Around line 22-37: The piholeClient shadow inside the Login/defer block is
intentional but easy to remove accidentally, so add a clarifying comment near
the piholeClient := piholeClient assignment in clients.go. Make it explicit that
the local copy is needed because the deferred Logout closure must not reference
the named return variable, which gets zeroed on the early return path before
defer runs.

In `@pkg/clients/pihole/pihole.go`:
- Around line 75-79: The logout flow in pihole.go logs “Logged out from Pi-Hole”
unconditionally even when Logout returns a failure status, which makes the debug
output misleading. In the Logout method, gate the success debug log on a
non-error statusCode or move it into the success path so it only prints when the
logout actually succeeds; keep the existing warning for statusCode >= 400 and
use the Logout and log.Debug/log.Warn calls to place the messages correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8cc14bca-19ab-44d7-b8fe-9561851199e8

📥 Commits

Reviewing files that changed from the base of the PR and between fe44839 and 5309e1a.

📒 Files selected for processing (3)
  • pkg/clients/clients.go
  • pkg/clients/common/common.go
  • pkg/clients/pihole/pihole.go

@DeepSpace2
DeepSpace2 force-pushed the fix-pihole-sessions-cleanup-on-errors branch from 5309e1a to 8913260 Compare July 7, 2026 13:07
@DeepSpace2
DeepSpace2 merged commit 3201f50 into master Jul 7, 2026
8 checks passed
@DeepSpace2
DeepSpace2 deleted the fix-pihole-sessions-cleanup-on-errors branch July 7, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant