CacheS - close precached channels

This commit is contained in:
DanB
2019-03-27 17:05:52 +01:00
parent 772322e6f4
commit d5ebc2af9e
2 changed files with 19 additions and 16 deletions

View File

@@ -1056,8 +1056,8 @@ func startRpc(server *utils.Server, internalRaterChan,
internalCdrSChan, internalRsChan, internalStatSChan,
internalAttrSChan, internalChargerSChan, internalThdSChan, internalSuplSChan,
internalSMGChan, internalAnalyzerSChan chan rpcclient.RpcClientConnection,
internalDispatcherSChan chan *dispatchers.DispatcherService, exitChan chan bool,
internalCacheSChan chan rpcclient.RpcClientConnection) {
internalDispatcherSChan chan *dispatchers.DispatcherService,
exitChan chan bool) {
select { // Any of the rpc methods will unlock listening to rpc requests
case resp := <-internalRaterChan:
internalRaterChan <- resp
@@ -1486,7 +1486,7 @@ func main() {
internalRsChan, internalStatSChan,
internalAttributeSChan, internalChargerSChan, internalThresholdSChan,
internalSupplierSChan, internalSMGChan, internalAnalyzerSChan,
internalDispatcherSChan, exitChan, internalCacheSChan)
internalDispatcherSChan, exitChan)
<-exitChan
if *cpuProfDir != "" { // wait to end cpuProfiling

View File

@@ -112,21 +112,24 @@ func (chS *CacheS) Precache() (err error) {
if !precachedPartitions.HasKey(cacheID) {
continue
}
if cacheCfg.Precache {
wg.Add(1)
go func() {
errCache := chS.dm.CacheDataFromDB(
utils.CacheInstanceToPrefix[cacheID], nil,
false)
if errCache != nil {
errChan <- errCache
}
close(chS.pcItems[cacheID])
wg.Done()
}()
if !cacheCfg.Precache {
close(chS.pcItems[cacheID]) // no need of precache
continue
}
wg.Add(1)
go func(cacheID string) {
errCache := chS.dm.CacheDataFromDB(
utils.CacheInstanceToPrefix[cacheID], nil,
false)
if errCache != nil {
errChan <- errCache
}
close(chS.pcItems[cacheID])
wg.Done()
}(cacheID)
}
go func() { // report wg.Wait on doneChan
time.Sleep(1) // switch context
go func() { // report wg.Wait on doneChan
wg.Wait()
close(doneChan)
}()