From eb796bd04f7af56d6639491e40e1b85775b23456 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Tue, 19 Aug 2025 21:51:10 +0300 Subject: [PATCH] ips: fix deadlock from cached allocs missing profile reference --- engine/datamanager.go | 12 +++++++----- utils/ips.go | 10 ++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/engine/datamanager.go b/engine/datamanager.go index 7874f5b58..02fddea43 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -1691,7 +1691,11 @@ func (dm *DataManager) GetIPAllocations(ctx *context.Context, tenant, id string, if x == nil { return nil, utils.ErrNotFound } - return x.(*utils.IPAllocations), nil + ip = x.(*utils.IPAllocations) + if err = ip.ComputeUnexported(prfl); err != nil { + return nil, err + } + return ip, nil } } if dm == nil { @@ -1724,10 +1728,8 @@ func (dm *DataManager) GetIPAllocations(ctx *context.Context, tenant, id string, return nil, err } } - if prfl != nil { - if err = ip.ComputeUnexported(prfl); err != nil { - return nil, err - } + if err = ip.ComputeUnexported(prfl); err != nil { + return nil, err } if cacheWrite { if errCh := Cache.Set(ctx, utils.CacheIPAllocations, tntID, ip, nil, diff --git a/utils/ips.go b/utils/ips.go index c02d7c258..4b77432b2 100644 --- a/utils/ips.go +++ b/utils/ips.go @@ -425,9 +425,15 @@ type ClearIPAllocationsArgs struct { APIOpts map[string]any } -// ComputeUnexported populates lookup maps and profile reference from exported fields. -// Must be called after retrieving from DB. +// ComputeUnexported sets up unexported fields based on the provided profile. +// Safe to call multiple times with the same profile. func (a *IPAllocations) ComputeUnexported(prfl *IPProfile) error { + if prfl == nil { + return nil // nothing to compute without a profile + } + if a.prfl == prfl { + return nil // already computed for this profile + } a.prfl = prfl a.poolAllocs = make(map[string]map[netip.Addr]string) for allocID, alloc := range a.Allocations {