Better locking of session debitLoop chan

This commit is contained in:
Trial97
2020-09-29 15:54:08 +03:00
committed by Dan Christian Bogos
parent 225492cfe5
commit 8e3ca35a77

View File

@@ -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