Skip to content

Commit aeebb3c

Browse files
oktalzmjuraga
authored andcommitted
BUG/MEDIUM: raw: when changing runtimes, allow some time for new socket to be ready
use 1,2,4,8 seconds intervals between checking
1 parent 7c9cc84 commit aeebb3c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

handlers/raw.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ import (
2020
"fmt"
2121
"strconv"
2222
"strings"
23+
"time"
2324

2425
"github.com/go-openapi/runtime/middleware"
2526
client_native "github.com/haproxytech/client-native/v3"
2627
"github.com/haproxytech/client-native/v3/models"
28+
"github.com/haproxytech/client-native/v3/runtime"
2729

2830
cn "github.com/haproxytech/dataplaneapi/client-native"
2931
dataplaneapi_config "github.com/haproxytech/dataplaneapi/configuration"
3032
"github.com/haproxytech/dataplaneapi/haproxy"
33+
"github.com/haproxytech/dataplaneapi/log"
3134
"github.com/haproxytech/dataplaneapi/misc"
3235
"github.com/haproxytech/dataplaneapi/operations/configuration"
3336
)
@@ -196,7 +199,22 @@ func (h *PostRawConfigurationHandlerImpl) reconfigureRuntime(runtimeAPIsOld []*m
196199
dpapiCfg := dataplaneapi_config.Get()
197200
haproxyOptions := dpapiCfg.HAProxy
198201
return true, func() {
199-
h.Client.ReplaceRuntime(cn.ConfigureRuntimeClient(context.Background(), cfg, haproxyOptions))
202+
var rnt runtime.Runtime
203+
i := 1
204+
for i < 10 {
205+
rnt = cn.ConfigureRuntimeClient(context.Background(), cfg, haproxyOptions)
206+
if rnt != nil {
207+
break
208+
}
209+
time.Sleep(time.Duration(i) * time.Second)
210+
i += i // exponential backoof
211+
}
212+
h.Client.ReplaceRuntime(rnt)
213+
if rnt == nil {
214+
log.Debugf("reload callback completed, no runtime API")
215+
} else {
216+
log.Debugf("reload callback completed, runtime API reconfigured")
217+
}
200218
}, nil
201219
}
202220

0 commit comments

Comments
 (0)