Skip to content

Commit

Permalink
BUG/MEDIUM: raw: when changing runtimes, allow some time for new sock…
Browse files Browse the repository at this point in the history
…et to be ready

use 1,2,4,8 seconds intervals between checking
  • Loading branch information
oktalz authored and mjuraga committed Apr 6, 2022
1 parent 7c9cc84 commit aeebb3c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion handlers/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/go-openapi/runtime/middleware"
client_native "github.com/haproxytech/client-native/v3"
"github.com/haproxytech/client-native/v3/models"
"github.com/haproxytech/client-native/v3/runtime"

cn "github.com/haproxytech/dataplaneapi/client-native"
dataplaneapi_config "github.com/haproxytech/dataplaneapi/configuration"
"github.com/haproxytech/dataplaneapi/haproxy"
"github.com/haproxytech/dataplaneapi/log"
"github.com/haproxytech/dataplaneapi/misc"
"github.com/haproxytech/dataplaneapi/operations/configuration"
)
Expand Down Expand Up @@ -196,7 +199,22 @@ func (h *PostRawConfigurationHandlerImpl) reconfigureRuntime(runtimeAPIsOld []*m
dpapiCfg := dataplaneapi_config.Get()
haproxyOptions := dpapiCfg.HAProxy
return true, func() {
h.Client.ReplaceRuntime(cn.ConfigureRuntimeClient(context.Background(), cfg, haproxyOptions))
var rnt runtime.Runtime
i := 1
for i < 10 {
rnt = cn.ConfigureRuntimeClient(context.Background(), cfg, haproxyOptions)
if rnt != nil {
break
}
time.Sleep(time.Duration(i) * time.Second)
i += i // exponential backoof
}
h.Client.ReplaceRuntime(rnt)
if rnt == nil {
log.Debugf("reload callback completed, no runtime API")
} else {
log.Debugf("reload callback completed, runtime API reconfigured")
}
}, nil
}

Expand Down

0 comments on commit aeebb3c

Please sign in to comment.