mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
ips: fix deadlock from cached allocs missing profile reference
This commit is contained in:
committed by
Dan Christian Bogos
parent
44df79fe7b
commit
eb796bd04f
@@ -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,
|
||||
|
||||
10
utils/ips.go
10
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 {
|
||||
|
||||
Reference in New Issue
Block a user