mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
possible fix for concurent map access in smg_event
This commit is contained in:
@@ -140,7 +140,7 @@ func (self DiameterAgent) processCCR(ccr *CCR, reqProcessor *config.DARequestPro
|
||||
if ccr.CCRequestType == 3 {
|
||||
err = self.smg.Call("SMGenericV1.TerminateSession", smgEv, &rpl)
|
||||
} else if ccr.CCRequestType == 4 {
|
||||
err = self.smg.Call("SMGenericV1.ChargeEvent", smgEv, &maxUsage)
|
||||
err = self.smg.Call("SMGenericV1.ChargeEvent", smgEv.Clone(), &maxUsage)
|
||||
if maxUsage == 0 {
|
||||
smgEv[utils.USAGE] = 0 // For CDR not to debit
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@ package cache2go
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// Cache is an LRU cache. It is not safe for concurrent access.
|
||||
@@ -151,8 +154,12 @@ func (c *Cache) removeElement(e *list.Element) {
|
||||
}
|
||||
}
|
||||
}
|
||||
kv := e.Value.(*entry)
|
||||
delete(c.cache, kv.key)
|
||||
if e.Value != nil {
|
||||
kv := e.Value.(*entry)
|
||||
delete(c.cache, kv.key)
|
||||
} else {
|
||||
utils.Logger.Debug(fmt.Sprintf("<lruttl_cache>: nil element: %+v", e))
|
||||
}
|
||||
}
|
||||
|
||||
// Len returns the number of items in the cache.
|
||||
|
||||
@@ -29,7 +29,7 @@ func TestCacheExpire(t *testing.T) {
|
||||
if !ok || b == nil || b != a {
|
||||
t.Error("Error retriving data from cache", b)
|
||||
}
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
b, ok = cache.Get("mama")
|
||||
if ok || b != nil {
|
||||
t.Error("Error expiring data from cache", b)
|
||||
|
||||
@@ -429,7 +429,7 @@ func (self SMGenericEvent) AsLcrRequest() *engine.LcrRequest {
|
||||
|
||||
// AsMapStringString Converts into map[string]string, used for example as pubsub event
|
||||
func (self SMGenericEvent) AsMapStringString() (map[string]string, error) {
|
||||
mp := make(map[string]string)
|
||||
mp := make(map[string]string, len(self))
|
||||
for k, v := range self {
|
||||
if strV, casts := utils.CastIfToString(v); !casts {
|
||||
return nil, fmt.Errorf("Value %+v does not cast to string", v)
|
||||
@@ -439,3 +439,11 @@ func (self SMGenericEvent) AsMapStringString() (map[string]string, error) {
|
||||
}
|
||||
return mp, nil
|
||||
}
|
||||
|
||||
func (self SMGenericEvent) Clone() SMGenericEvent {
|
||||
evOut := make(SMGenericEvent, len(self))
|
||||
for key, val := range self {
|
||||
evOut[key] = val
|
||||
}
|
||||
return evOut
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ func ConvertMapValStrIf(inMap map[string]string) map[string]interface{} {
|
||||
}
|
||||
|
||||
// Mirrors key/val
|
||||
func MirrorMap(mapIn map[string]string) (map[string]string, error) {
|
||||
mapOut := make(map[string]string)
|
||||
func MirrorMap(mapIn map[string]string) map[string]string {
|
||||
mapOut := make(map[string]string, len(mapIn))
|
||||
for key, val := range mapIn {
|
||||
mapOut[val] = key
|
||||
}
|
||||
return mapOut, nil
|
||||
return mapOut
|
||||
}
|
||||
|
||||
// Returns mising keys in a map
|
||||
|
||||
Reference in New Issue
Block a user