refactor(ipscanner): isolate scanner activations (3/9) - #782
Conversation
🔐 Codex Security Review
Review SummaryOverall Risk: NONE FindingsNo security, correctness, or reliability findings were identified in the scoped diff. NotesReviewed only Generated by Codex Security Review | |
f422020 to
1c7da92
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c7da92519
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
- Keep scanner activations alive after startup context cancellation - Add regression coverage for lifecycle-owned cancellation
Reviewable diff: +90/-53 across 2 files (excludes generated, test, and story files).
Summary
IP discovery now has activation-scoped queues and bounded shutdown, preventing one Fleet activation from leaking scan work or results into the next. Standalone scanning keeps its current startup behavior while gaining a clean
Start -> Stop -> Startpath.Stack:
fleetdcutover: #788This PR is the IP scanner lifecycle slice and now targets
main. Merged #780 supplies the sharedruntimejobs.Lifecyclecontract; the remaining domain and orchestration refactors are independent sibling PRs and can merge in any order. #788 is temporarily based on the integration branch so its reviewable diff contains only catalog/cutover work; after the siblings merge it will be rebased and retargeted tomain. Passive-mode coordinator wiring, epoch fencing, and request gating remain later HA work.How it works
Before this PR, the scanner's task queue, result queue, cancellation function, and goroutine tracking belonged to the long-lived service and assumed one activation for the lifetime of the process. Adding a lifecycle interface around that state would not make it safely restartable: buffered work could cross into a later activation, a worker blocked while publishing a result could prevent shutdown, and a timed-out stop could otherwise be followed by an overlapping start.
Each successful
Startnow creates fresh task and result channels plus service-owned cancellation, then launches the scanner workers for that activation. Worker sends select on cancellation, so a full result queue cannot trap shutdown.Stopcancels producers and consumers, waits for every activation-owned goroutine within the caller's deadline, and only then permits restart. The underlying discovery flow—selecting offline devices, grouping them by subnet, verifying identity, and persisting a corrected address—remains unchanged.flowchart LR S["Start activation"] --> Q["Fresh task and result queues"] Q --> W["Scanner workers"] W --> C["Cancellation-aware result send"] X["Stop"] --> C X --> D["Drain activation goroutines"] D --> R["Fresh later activation"]Areas of the code involved
server/internal/domain/ipscanner/service.goserver/cmd/fleetd/main.goKey technical decisions & trade-offs
stoppingstate so restart cannot overlap surviving scanner work.Related
Related: #740
Testing & validation
go test -short -race -count=1 ./internal/domain/ipscanner ./cmd/fleetdPost-Deploy Monitoring & Validation
Watch IP scanner errors, scan completion rates, and shutdown drain logs through one normal scan interval. Roll back if scans stop being scheduled, discovered devices stop appearing, or scanner shutdown repeatedly exceeds its budget.