opensnitch/daemon/ui
Ted Robertson 5e12a0baef daemon: fix data race in getClientConfig iterating rules during load
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.
2026-05-19 02:03:26 -07:00
..
auth more work on reloading configuration 2024-05-11 18:23:20 +02:00
config tasks: allow to load tasks from disk 2025-09-11 12:19:38 +02:00
protocol makefile: 2021-02-13 18:48:49 +03:00
testdata config tests: added missing comma 2025-09-11 00:29:02 +02:00
alerts.go fixed leak dispatching alerts 2023-12-31 20:12:44 +01:00
client.go avoid to send empty stats to the GUI (server) 2025-12-11 12:07:10 +01:00
client_test.go updated config tests 2025-06-19 23:49:45 +02:00
config_utils.go tasks: allow to load tasks from disk 2025-09-11 12:19:38 +02:00
notifications.go daemon: fix data race in getClientConfig iterating rules during load 2026-05-19 02:03:26 -07:00
notifications_tasks.go print the notifications type on error 2025-11-27 21:32:39 +01:00