Handle logical race condition when caching exporters

- added lock to ensure only one exporter instance is cached.
- marked duplicate instances to be closed after export.
This commit is contained in:
ionutboangiu
2024-06-30 10:01:03 +03:00
committed by Dan Christian Bogos
parent 02ae2cce79
commit 9c94fbfe58

View File

@@ -218,7 +218,15 @@ func (eeS *EventExporterS) V1ProcessEvent(ctx *context.Context, cgrEv *engine.CG
return
}
if hasCache {
eeCache.Set(eeCfg.ID, ee, nil)
eeS.eesMux.Lock()
if _, has := eeCache.Get(eeCfg.ID); !has {
eeCache.Set(eeCfg.ID, ee, nil)
} else {
// Another exporter instance with the same ID has been cached in
// the meantime. Mark this instance to be closed after the export.
hasCache = false
}
eeS.eesMux.Unlock()
}
}