From 9c94fbfe5813da910f124e821c70ac3fea973bbb Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Sun, 30 Jun 2024 10:01:03 +0300 Subject: [PATCH] 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. --- ees/ees.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ees/ees.go b/ees/ees.go index d502a2cf7..990dfd8fb 100644 --- a/ees/ees.go +++ b/ees/ees.go @@ -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() } }