Loader.GetAll() returned the loader internal map by reference under an RLock that was released as the call returned. getClientConfig() then called GetAll() twice -- once for len() to size a slice, once to range over the entries -- without holding any lock. A concurrent goroutine (e.g. the loader still synchronously processing rules during reloadConfiguration) writing to the map between the two calls makes the iteration yield more entries than the pre-sized slice, panicking with "index out of range [N] with length N". On bad luck the Go runtime trips "concurrent map iteration and map write" instead. The race is reachable on real systems whenever the UI poller, started by reloadConfiguration via c.Connect(), reconnects before c.rules.Reload(path) finishes loading rules from disk. Consistently reproducible with ~2100 rules on disk. Make GetAll() return a shallow snapshot of the rule map under the read lock so length and iteration are guaranteed consistent for the caller. Update the one caller (getClientConfig) to take the snapshot once. Add a regression test running concurrent writers and readers against the loader; -race catches the original bug, and the new GetAll contract makes it pass. |
||
|---|---|---|
| .. | ||
| auth | ||
| config | ||
| protocol | ||
| testdata | ||
| alerts.go | ||
| client.go | ||
| client_test.go | ||
| config_utils.go | ||
| notifications.go | ||
| notifications_tasks.go | ||