Skip to content

Commit

Permalink
Fixed ctx deadline exceeded errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Aug 12, 2023
1 parent 5e62ffd commit b270f03
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,6 @@ loop:
klog.Infof("loxilb-client (%s) : purged", purgedClient.Host)
case aliveClient := <-loxiAliveCh:
aliveClient.DoBGPCfg = false
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
if m.networkConfig.SetRoles && !aliveClient.PeeringOnly {

if !m.ElectionRunOnce {
Expand All @@ -1277,7 +1275,12 @@ loop:
cisModel, err := m.makeLoxiLBCIStatusModel("default", aliveClient)
if err == nil {
for retry := 0; retry < 5; retry++ {
if err := aliveClient.CIStatus().Create(ctx, &cisModel); err == nil {
err = func(cisModel *api.CIStatusModel) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
return aliveClient.CIStatus().Create(ctx, cisModel)
}(&cisModel)
if err == nil {
klog.Infof("%v: set-role-master(%v) - OK", aliveClient.Host, aliveClient.MasterLB)
break
} else {
Expand Down Expand Up @@ -1306,7 +1309,13 @@ loop:
} else {
bgpGlobalCfg, _ = m.makeLoxiLBBGPGlobalModel(int(m.networkConfig.SetBGP), aliveClient.Host, true, m.networkConfig.ListenBGPPort)
}
if err := aliveClient.BGP().CreateGlobalConfig(ctx, &bgpGlobalCfg); err == nil {
err := func(bgpGlobalCfg *api.BGPGlobalConfig) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
return aliveClient.BGP().CreateGlobalConfig(ctx, bgpGlobalCfg)
}(&bgpGlobalCfg)

if err == nil {
klog.Infof("set-bgp-global success")
} else {
klog.Infof("set-bgp-global failed(%s)", err)
Expand All @@ -1315,15 +1324,25 @@ loop:

for _, bgpPeer := range bgpPeers {
bgpNeighCfg, _ := m.makeLoxiLBBGNeighModel(int(m.networkConfig.SetBGP), bgpPeer.Host, m.networkConfig.ListenBGPPort)
if err := aliveClient.BGP().CreateNeigh(ctx, &bgpNeighCfg); err == nil {
err := func(bgpNeighCfg *api.BGPNeigh) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
return aliveClient.BGP().CreateNeigh(ctx, bgpNeighCfg)
}(&bgpNeighCfg)
if err == nil {
klog.Infof("set-bgp-neigh(%s->%s) success", aliveClient.Host, bgpPeer.Host)
} else {
klog.Infof("set-bgp-neigh(%s->%s) failed(%s)", aliveClient.Host, bgpPeer.Host, err)
m.checkHandleBGPCfgErrors(loxiAliveCh, aliveClient, err)
}

bgpNeighCfg1, _ := m.makeLoxiLBBGNeighModel(int(m.networkConfig.SetBGP), aliveClient.Host, m.networkConfig.ListenBGPPort)
if err := bgpPeer.BGP().CreateNeigh(ctx, &bgpNeighCfg1); err == nil {
err = func(bgpNeighCfg1 *api.BGPNeigh) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
return bgpPeer.BGP().CreateNeigh(ctx, bgpNeighCfg1)
}(&bgpNeighCfg1)
if err == nil {
klog.Infof("set-bgp-neigh(%s->%s) success", bgpPeer.Host, aliveClient.Host)
} else {
klog.Infof("set-bgp-neigh(%s->%s) failed(%s)", bgpPeer.Host, aliveClient.Host, err)
Expand All @@ -1349,7 +1368,12 @@ loop:
}

bgpNeighCfg, _ := m.makeLoxiLBBGNeighModel(int(asid), bgpRemoteIP.String(), 0)
if err := aliveClient.BGP().CreateNeigh(ctx, &bgpNeighCfg); err == nil {
err = func(bgpNeighCfg *api.BGPNeigh) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
return aliveClient.BGP().CreateNeigh(ctx, bgpNeighCfg)
}(&bgpNeighCfg)
if err == nil {
klog.Infof("set-ebgp-neigh(%s:%v) cfg success", bgpRemoteIP.String(), asid)
} else {
klog.Infof("set-ebgp-neigh(%s:%v) cfg - failed (%s)", bgpRemoteIP.String(), asid, err)
Expand All @@ -1364,7 +1388,12 @@ loop:
for _, value := range m.lbCache {
for _, lbModel := range value.LbModelList {
for retry := 0; retry < 5; retry++ {
if err := aliveClient.LoadBalancer().Create(ctx, &lbModel); err == nil {
err := func(lbModel *api.LoadBalancerModel) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
return aliveClient.LoadBalancer().Create(ctx, lbModel)
}(&lbModel)
if err == nil {
klog.Infof("reinstallLoxiLbRules: lbModel: %v success", lbModel)
isSuccess = true
break
Expand Down

0 comments on commit b270f03

Please sign in to comment.