From 30ebb6c5eb29d5e83864b98a7ad3c4119b55876a Mon Sep 17 00:00:00 2001 From: Kornilios Kourtis Date: Wed, 29 May 2024 15:45:34 +0200 Subject: [PATCH] sensors: allow listing policies while enabling This patch modifies disableTracingPolicy to release the lock to the collections while enabling a sensor. Before releasing the lock, the state is changed to LoadingState. Signed-off-by: Kornilios Kourtis --- pkg/sensors/handler.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/sensors/handler.go b/pkg/sensors/handler.go index dd8cd4ae526..382b8a310dd 100644 --- a/pkg/sensors/handler.go +++ b/pkg/sensors/handler.go @@ -218,9 +218,15 @@ func (h *handler) enableTracingPolicy(op *tracingPolicyEnable) error { return fmt.Errorf("tracing policy %s is not disabled", op.ck) } - if err := col.load(h.bpfDir); err != nil { + col.state = LoadingState + // unlock so that policyLister can access the collections (read-only) while we are loading. + h.collections.mu.Unlock() + err := col.load(h.bpfDir) + h.collections.mu.Lock() + + if err != nil { col.state = LoadErrorState - col.err = fmt.Errorf("failed to load tracing policy %q: %w", col.name, err) + col.err = fmt.Errorf("failed to enable tracing policy %q: %w", col.name, err) return col.err }