This commit is contained in:
andig 2026-02-24 11:40:52 +01:00
parent c3cd6e41cd
commit 1e509e4f6e

View file

@ -182,17 +182,18 @@ func NewWarpWS(ctx context.Context, uri, user, password string, meterIndex uint)
}
}
go w.run(uri, user, password, ctx)
go w.run(ctx, uri, user, password)
return w, nil
}
func (w *WarpWS) run(uri, user, pass string, ctx context.Context) {
bo := backoff.NewExponentialBackOff(backoff.WithMaxElapsedTime(0))
bo.MaxInterval = 30 * time.Second
func (w *WarpWS) run(ctx context.Context, uri, user, pass string) {
bo := backoff.NewExponentialBackOff(
backoff.WithMaxInterval(30*time.Second),
backoff.WithMaxElapsedTime(0))
for ctx.Err() == nil {
w.log.DEBUG.Printf("ws connecting to %s …", uri)
w.log.DEBUG.Printf("ws connecting to %s", uri)
conn, resp, err := dialWebsocket(ctx, uri, user, pass)
if err != nil {
@ -212,16 +213,10 @@ func (w *WarpWS) run(uri, user, pass string, ctx context.Context) {
}
}
if ctx.Err() != nil {
return
}
d := bo.NextBackOff()
w.log.DEBUG.Printf("ws reconnecting to %s in %v", uri, d)
select {
case <-ctx.Done():
return
case <-time.After(d):
case <-time.After(bo.NextBackOff()):
}
}
}