mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Connect to dispatcher only when the call is made
This commit is contained in:
committed by
Dan Christian Bogos
parent
530dd6fa59
commit
72d1e7fd2f
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/ltcache"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -2958,20 +2957,10 @@ func (dm *DataManager) GetDispatcherHost(tenant, id string, cacheRead, cacheWrit
|
||||
}
|
||||
}
|
||||
if cacheWrite {
|
||||
cfg := config.CgrConfig()
|
||||
if dH.rpcConn, err = NewRPCPool( // send it wil lazy connect on true and try to connect only when the call is make
|
||||
rpcclient.PoolFirst,
|
||||
cfg.TlsCfg().ClientKey,
|
||||
cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate,
|
||||
cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects,
|
||||
cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout,
|
||||
dH.Conns, IntRPC.GetInternalChanel(), true); err != nil {
|
||||
if err = Cache.Set(utils.CacheDispatcherHosts, tntID, dH, nil,
|
||||
cacheCommit(transactionID), transactionID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if errCh := Cache.Set(utils.CacheDispatcherHosts, tntID, dH, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
return nil, errCh
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"net"
|
||||
"net/rpc"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -244,11 +243,10 @@ func IsNetworkError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
if operr, ok := err.(*net.OpError); ok &&
|
||||
(strings.HasSuffix(operr.Err.Error(),
|
||||
syscall.ECONNRESET.Error()) ||
|
||||
(strings.HasSuffix(operr.Err.Error(),
|
||||
syscall.ECONNREFUSED.Error()))) { // connection reset
|
||||
if _, isNetError := err.(*net.OpError); isNetError { // connection reset
|
||||
return true
|
||||
}
|
||||
if _, isDNSError := err.(*net.DNSError); isDNSError {
|
||||
return true
|
||||
}
|
||||
return err.Error() == rpc.ErrShutdown.Error() ||
|
||||
@@ -256,8 +254,7 @@ func IsNetworkError(err error) bool {
|
||||
err.Error() == ErrDisconnected.Error() ||
|
||||
err.Error() == ErrReplyTimeout.Error() ||
|
||||
err.Error() == ErrSessionNotFound.Error() ||
|
||||
strings.HasPrefix(err.Error(), "rpc: can't find service") ||
|
||||
strings.HasSuffix(err.Error(), "no such host")
|
||||
strings.HasPrefix(err.Error(), "rpc: can't find service")
|
||||
}
|
||||
|
||||
func ErrPathNotReachable(path string) error {
|
||||
|
||||
Reference in New Issue
Block a user