Skip to content

fix: close pi-hole sessions#55

Merged
DeepSpace2 merged 4 commits into
masterfrom
fix-issue-50-close-pihole-sessions
Jun 26, 2026
Merged

fix: close pi-hole sessions#55
DeepSpace2 merged 4 commits into
masterfrom
fix-issue-50-close-pihole-sessions

Conversation

@DeepSpace2

@DeepSpace2 DeepSpace2 commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Closes #50

Summary by CodeRabbit

  • New Features

    • Improved graceful shutdown now performs a cleaner sign-out step before the app exits.
  • Bug Fixes

    • Better handling of expired or missing Pi-hole sessions during DNS and CNAME operations.
    • Authentication refresh is now more reliable and reports failures more clearly.
    • Session data is cleared after logout, even if the server returns an error response.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5946b9f9-c585-4298-94b7-2d24ec685f36

📥 Commits

Reviewing files that changed from the base of the PR and between a40b73b and 3e21710.

📒 Files selected for processing (6)
  • e2e_tests/e2e_test.go
  • main.go
  • pkg/clients/clients.go
  • pkg/clients/common/common.go
  • pkg/clients/pihole/pihole.go
  • pkg/clients/pihole/pihole_test.go
📝 Walkthrough

Walkthrough

Pi-hole client authentication now supports logout, returns errors for missing sessions, refreshes auth by logging out before re-login, and calls logout during processor shutdown and graceful program termination.

Changes

Pi-hole session lifecycle

Layer / File(s) Summary
Logout API and tests
pkg/clients/pihole/pihole.go, pkg/clients/pihole/pihole_test.go
Client.Logout() sends DELETE /api/auth, clears stored credentials, and is covered by success, empty-session, and non-success cases.
Auth refresh and session errors
pkg/clients/pihole/errors.go, pkg/clients/pihole/pihole.go
Shared Pi-hole errors are added, missing-session paths return errMissingSessionId, and 401 recovery logs out the old session before re-login.
Shutdown wiring
pkg/processor/processor.go, main.go
Processor.Shutdown() logs out the Pi-hole client, and main calls it after context cancellation before waiting on goroutines.

Sequence Diagram(s)

sequenceDiagram
  participant main
  participant Processor
  participant PiholeClient
  participant PiHoleAPI
  main->>Processor: proc.Shutdown()
  Processor->>PiholeClient: Logout()
  PiholeClient->>PiHoleAPI: DELETE /api/auth
  PiHoleAPI-->>PiholeClient: response status
  PiholeClient-->>Processor: nil or error
  Processor-->>main: return
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: closing Pi-hole sessions.
Linked Issues check ✅ Passed The PR adds logout handling after runs and on auth refresh, which addresses the session leak described in #50.
Out of Scope Changes check ✅ Passed The changes all support Pi-hole session cleanup and authentication handling, with no clear unrelated additions.

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


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 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.

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@main.go`:
- Around line 79-82: `main()` is shutting down the Pi-hole client in the wrong
place: `proc.Shutdown()` is tied to the `ctx.Done()` branch, so it is skipped
for the `RUN_INTERVAL == 0` one-shot path and can also run before worker
goroutines finish. Move the shutdown/logout responsibility out of the
early-return path and ensure it happens after `wg.Wait()` in the `main` flow,
using the `proc`/`Shutdown()` and `wg` symbols to keep the client alive until
all in-flight work is complete.

In `@pkg/clients/pihole/pihole.go`:
- Around line 378-383: The refreshAuth flow is reusing p.password after Logout()
clears it, so Login(p.password) ends up using an empty password. In
Client.refreshAuth, preserve the current password in a local variable before
calling Logout(), then pass that saved value into Login() after logout succeeds;
use the existing refreshAuth, Logout, and Login symbols to update the 401
recovery path without losing credentials.

In `@pkg/processor/processor.go`:
- Around line 293-299: The Processor.Shutdown path currently performs a blocking
piholeClient.Logout call that can hang shutdown indefinitely if Pi-hole is
unreachable. Update Shutdown and the pihole.Client logout flow to use a bounded
timeout or context-aware cancellation, and make sure the Logout path (including
common.Delete) respects that deadline so shutdown cannot stall; keep the fix
localized around Processor.Shutdown, piholeClient.Logout, and the underlying
common.Delete call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 03bd710b-62be-4a9d-8559-d66aab4f3eb8

📥 Commits

Reviewing files that changed from the base of the PR and between 0b51807 and a40b73b.

📒 Files selected for processing (5)
  • main.go
  • pkg/clients/pihole/errors.go
  • pkg/clients/pihole/pihole.go
  • pkg/clients/pihole/pihole_test.go
  • pkg/processor/processor.go

Comment thread main.go
Comment thread pkg/clients/pihole/pihole.go Outdated
Comment thread pkg/processor/processor.go
@DeepSpace2 DeepSpace2 merged commit 05ca23f into master Jun 26, 2026
8 checks passed
@DeepSpace2 DeepSpace2 deleted the fix-issue-50-close-pihole-sessions branch June 26, 2026 08:37
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.

Pi-hole v6 API sessions are never closed (no logout) — exhausts webserver.api.max_sessions and 429s all clients

1 participant