fix: close pi-hole sessions#55
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughPi-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. ChangesPi-hole session lifecycle
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
main.gopkg/clients/pihole/errors.gopkg/clients/pihole/pihole.gopkg/clients/pihole/pihole_test.gopkg/processor/processor.go
Closes #50
Summary by CodeRabbit
New Features
Bug Fixes