ips: fix deadlock from cached allocs missing profile reference

This commit is contained in:
ionutboangiu
2025-08-19 21:51:10 +03:00
committed by Dan Christian Bogos
parent 44df79fe7b
commit eb796bd04f
2 changed files with 15 additions and 7 deletions

View File

@@ -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,

View File

@@ -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 {