fix: config reload concurrency hardening (#3, #4)#14
Conversation
#4: collector now reads Collect/Event via a per-gather config snapshot (config.TakeSnapshot under Config.Mutex), captured once at the top of Collect() and stashed on Client.cfg; discovery uses its own local snapshot. No internal/collector code reads config.Config.Collect/.Event directly anymore. Kills the reader-writer data race under -race. #3: the config watcher now performs the rename/remove watch re-attach BEFORE the 1s dedup gate, so an atomic editor save within the window no longer silently drops the inotify watch. The gate now suppresses only the redundant ReloadConfig call. Tests: -race gather-vs-reload test (#4); real-fsnotify atomic-save re-attach test (#3). make ci green (vet, golangci-lint 0, test -race, govulncheck). Closes #3 Closes #4 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 5 minutes and 20 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Fixes two pre-existing config-reload correctness bugs flagged by the Phase 2b review (PR #2), tracked as issues. No public-contract change.
Closes #3
Closes #4
#4 — collector data race
The collector read
config.Config.Collect/.EventwithoutConfig.Mutexwhile SIGHUP /--config-watch//reloadmutate them under it — a reader-writer race under-race.config.TakeSnapshot()copiesCollect+EventunderConfig.Mutexinto aConfigSnapshotvalue (both all-scalar structs → safe deep copy).Collector.Collect()and stashed onClient.cfg, so the whole scrape sees one consistent config (concurrent same-target scrapes already coalesce). Path discovery (findAllEndpoints, runs at creation) uses its own local snapshot.internal/collectorread sites repointed;grep -rn 'config\.Config\.\(Collect\|Event\)' internal/collector/is now zero in production code.#3 — watcher silently drops the watch
Atomic editor saves (write→rename) within the 1s dedup window hit the
breakbefore the rename/remove re-add, so the inotify watch was dropped and future edits stopped reloading. The handler now does the re-attach first, and the 1s gate suppresses only theReloadConfigcall.Tests
internal/collector/config_race_test.go— gathers while a goroutine mutatesCollect/Eventunder the mutex; clean undergo test -race(would race on the old code).cmd/idrac_exporter/watcher_reattach_test.go— realfsnotify: atomic-save within the window, then a later write still arrives (watch survived). Skips gracefully where the env can't attach a watch.WatchConfigloop, so it won't catch a regression ofWatchConfigitself. The production reorder is small and reviewed. A follow-up could extract the handler for direct testing.Validation
make cigreen —go vet,golangci-lint0 issues,go test -race ./...(56 tests),govulncheckclean🤖 Generated with Claude Code