From 6474c1076f900e06b70b5c5985aaa0bc9f16ca8a Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Tue, 13 Aug 2024 19:10:38 +0300 Subject: [PATCH] update rpcclient library (#4413) for more details: https://github.com/cgrates/rpcclient/pull/37 --- dispatchers/dispatchers.go | 4 ++-- dispatchers/libdispatcher.go | 19 +++++++------------ dispatchers/responder_it_test.go | 3 +-- engine/connmanager.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/dispatchers/dispatchers.go b/dispatchers/dispatchers.go index 1779f5b80..f0afadf9a 100644 --- a/dispatchers/dispatchers.go +++ b/dispatchers/dispatchers.go @@ -269,7 +269,7 @@ func (dS *DispatcherService) Dispatch(ev *utils.CGREvent, subsys string, ev.APIOpts[k] = v // dispatcher loop protection opts } if err = d.Dispatch(dS.dm, dS.fltrS, evNm, tnt, utils.EmptyString, dR, - serviceMethod, args, reply); !rpcclient.IsConnectionErr(err) && !rpcclient.IsServiceErr(err) { + serviceMethod, args, reply); !rpcclient.ShouldFailover(err) { return // dispatch success or specific error coming from upstream } } @@ -303,7 +303,7 @@ func (dS *DispatcherService) Dispatch(ev *utils.CGREvent, subsys string, Tenant: dPrfl.Tenant, ProfileID: dPrfl.ID, }, - serviceMethod, args, reply); !rpcclient.IsConnectionErr(err) && !rpcclient.IsServiceErr(err) { + serviceMethod, args, reply); !rpcclient.ShouldFailover(err) { return } } diff --git a/dispatchers/libdispatcher.go b/dispatchers/libdispatcher.go index 1845d665f..6bbbc2800 100644 --- a/dispatchers/libdispatcher.go +++ b/dispatchers/libdispatcher.go @@ -229,9 +229,8 @@ func (sd *singleResultDispatcher) Dispatch(dm *engine.DataManager, flts *engine. } } if err = callDHwithID(tnt, hostID, routeID, dRh, dm, - serviceMethod, args, reply); err == nil || - (err != utils.ErrDSPHostNotFound && - !rpcclient.IsConnectionErr(err) && !rpcclient.IsServiceErr(err)) { // successful dispatch with normal errors + serviceMethod, args, reply); err != utils.ErrDSPHostNotFound && + !rpcclient.ShouldFailover(err) { // successful dispatch with normal errors return } if err != nil { @@ -314,10 +313,8 @@ func (ld *loadDispatcher) Dispatch(dm *engine.DataManager, flts *engine.FilterS, lM.incrementLoad(dR.HostID, ld.tntID) err = callDHwithID(tnt, dR.HostID, routeID, dR, dm, serviceMethod, args, reply) - lM.decrementLoad(dR.HostID, ld.tntID) // call ended - if err == nil || - (err != utils.ErrDSPHostNotFound && - !rpcclient.IsConnectionErr(err) && !rpcclient.IsServiceErr(err)) { // successful dispatch with normal errors + lM.decrementLoad(dR.HostID, ld.tntID) // call ended + if err != utils.ErrDSPHostNotFound && !rpcclient.ShouldFailover(err) { // successful dispatch with normal errors return } // not found or network errors will continue with standard dispatching @@ -342,10 +339,8 @@ func (ld *loadDispatcher) Dispatch(dm *engine.DataManager, flts *engine.FilterS, lM.incrementLoad(hostID, ld.tntID) err = callDHwithID(tnt, hostID, routeID, dRh, dm, serviceMethod, args, reply) - lM.decrementLoad(hostID, ld.tntID) // call ended - if err == nil || - (err != utils.ErrDSPHostNotFound && - !rpcclient.IsConnectionErr(err) && !rpcclient.IsServiceErr(err)) { // successful dispatch with normal errors + lM.decrementLoad(hostID, ld.tntID) // call ended + if err != utils.ErrDSPHostNotFound && !rpcclient.ShouldFailover(err) { // successful dispatch with normal errors return } if err != nil { @@ -457,7 +452,7 @@ func callDH(dh *engine.DispatcherHost, routeID string, dR *DispatcherRoute, GroupIDs: []string{utils.ConcatenatedKey(utils.CacheDispatcherProfiles, dR.Tenant, dR.ProfileID)}, } if err = engine.Cache.SetWithReplicate(argsCache); err != nil { - if !rpcclient.IsConnectionErr(err) && !rpcclient.IsServiceErr(err) { + if !rpcclient.ShouldFailover(err) { return } // did not dispatch properly, fail-back to standard dispatching diff --git a/dispatchers/responder_it_test.go b/dispatchers/responder_it_test.go index 9cb602a21..9d1b591a0 100644 --- a/dispatchers/responder_it_test.go +++ b/dispatchers/responder_it_test.go @@ -194,8 +194,7 @@ func testDspResponderBroadcast(t *testing.T) { allEngine.stopEngine(t) time.Sleep(10 * time.Millisecond) pingReply = "" - if err := dispEngine.RPC.Call(context.Background(), utils.ResponderPing, pingEv, &pingReply); err == nil || - !rpcclient.IsConnectionErr(err) && !rpcclient.IsServiceErr(err) { + if err := dispEngine.RPC.Call(context.Background(), utils.ResponderPing, pingEv, &pingReply); !rpcclient.ShouldFailover(err) { t.Errorf("Expected error: %s received error: %v and reply %q", utils.ErrPartiallyExecuted.Error(), err, pingReply) } allEngine.startEngine(t) diff --git a/engine/connmanager.go b/engine/connmanager.go index 634430750..f28ff6562 100644 --- a/engine/connmanager.go +++ b/engine/connmanager.go @@ -183,7 +183,7 @@ func (cM *ConnManager) Call(ctx *context.Context, connIDs []string, method strin if err != nil { continue } - if err = conn.Call(ctx, method, arg, reply); !rpcclient.IsConnectionErr(err) && !rpcclient.IsServiceErr(err) { + if err = conn.Call(ctx, method, arg, reply); !rpcclient.ShouldFailover(err) { return } } @@ -222,7 +222,7 @@ func (cM *ConnManager) CallWithConnIDs(connIDs []string, subsHostIDs utils.Strin if conn, err = cM.getConnWithConfig(context.TODO(), connID, newCfg, nil); err != nil { continue } - if err = conn.Call(context.TODO(), method, arg, reply); !!rpcclient.IsConnectionErr(err) && !rpcclient.IsServiceErr(err) { + if err = conn.Call(context.TODO(), method, arg, reply); !rpcclient.ShouldFailover(err) { return } } diff --git a/go.mod b/go.mod index b133a9817..7aed74588 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/cgrates/kamevapi v0.0.0-20240307160311-26273f03eedf github.com/cgrates/ltcache v0.0.0-20240411152156-e673692056db github.com/cgrates/radigo v0.0.0-20240123163129-491c899df727 - github.com/cgrates/rpcclient v0.0.0-20240628101047-cb29aae6b006 + github.com/cgrates/rpcclient v0.0.0-20240813140209-439c79036e27 github.com/cgrates/sipingo v1.0.1-0.20200514112313-699ebc1cdb8e github.com/creack/pty v1.1.20 github.com/dgrijalva/jwt-go v3.2.0+incompatible diff --git a/go.sum b/go.sum index b0da5ac21..85d8012a4 100644 --- a/go.sum +++ b/go.sum @@ -80,8 +80,8 @@ github.com/cgrates/ltcache v0.0.0-20240411152156-e673692056db h1:JRgzMS5kJ1Wxave github.com/cgrates/ltcache v0.0.0-20240411152156-e673692056db/go.mod h1:jVYq943GCWxhXXxi/1NthN9ATeyFUSbwJRbN/bb+ADQ= github.com/cgrates/radigo v0.0.0-20240123163129-491c899df727 h1:rhYHlbfEPDNreekd1ZtUYi/NbFm5cEl8twQZ3c/0nYU= github.com/cgrates/radigo v0.0.0-20240123163129-491c899df727/go.mod h1:W/5LcOm9jaz0NfIFT09bxjddEai8DTSfw9poqDqtAX4= -github.com/cgrates/rpcclient v0.0.0-20240628101047-cb29aae6b006 h1:HxmDpmCesrwbi+ag/4+PDRhuSy0gpemMRQ19fAWmDTE= -github.com/cgrates/rpcclient v0.0.0-20240628101047-cb29aae6b006/go.mod h1:WxTEIJvgI4c3eiPWW0WeAhHGd49Oi1Voe9lahotJiNo= +github.com/cgrates/rpcclient v0.0.0-20240813140209-439c79036e27 h1:wnaRqfM3+c/fjH0gtP6jJANcKipE9LfnYr9UysYg/+o= +github.com/cgrates/rpcclient v0.0.0-20240813140209-439c79036e27/go.mod h1:WxTEIJvgI4c3eiPWW0WeAhHGd49Oi1Voe9lahotJiNo= github.com/cgrates/sipingo v1.0.1-0.20200514112313-699ebc1cdb8e h1:izFjZB83/XRXInc+gMIssUxdbleGsGIuGCPj2u7RQo0= github.com/cgrates/sipingo v1.0.1-0.20200514112313-699ebc1cdb8e/go.mod h1:0f2+3dq5Iiv3VlcuY83VPJ0QzqRlzDG1Cr8okogQE3g= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=