diff --git a/sessions/sessions.go b/sessions/sessions.go index 6be890eeb..68a30d729 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -1149,6 +1149,7 @@ func (sS *SessionS) transitSState(cgrID string, psv bool) (s *Session) { return } s = ss[0] + s.Lock() sS.unregisterSession(cgrID, !psv) sS.registerSession(s, psv) if !psv { @@ -1157,6 +1158,7 @@ func (sS *SessionS) transitSState(cgrID string, psv bool) (s *Session) { s.stopSTerminator() s.stopDebitLoops() } + s.Unlock() return } @@ -1639,8 +1641,8 @@ func (sS *SessionS) BiRPCv1SetPassiveSession(clnt rpcclient.ClientConnector, if aSs := sS.getSessions(s.CGRID, false); len(aSs) != 0 { // found active session, transit to passive aSs[0].Lock() sS.unregisterSession(s.CGRID, false) - s.stopSTerminator() - s.stopDebitLoops() + aSs[0].stopSTerminator() + aSs[0].stopDebitLoops() aSs[0].Unlock() } sS.registerSession(s, true) @@ -2179,7 +2181,10 @@ func (sS *SessionS) BiRPCv1InitiateSession(clnt rpcclient.ClientConnector, if err != nil { return err } - if s.debitStop != nil { //active debit + s.RLock() // avoid concurrency with activeDebit + isPrepaid := s.debitStop != nil + s.RUnlock() + if isPrepaid { //active debit rply.MaxUsage = sS.cgrCfg.SessionSCfg().MaxCallDuration } else { var maxUsage time.Duration @@ -3127,7 +3132,10 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, if err != nil { return err } - if s.debitStop != nil { //active debit + s.RLock() + isPrepaid := s.debitStop != nil + s.RUnlock() + if isPrepaid { //active debit rply.MaxUsage = sS.cgrCfg.SessionSCfg().MaxCallDuration } else { var maxUsage time.Duration