Skip to content

Commit

Permalink
Force zero duration delay in retry loop
Browse files Browse the repository at this point in the history
  • Loading branch information
echlebek committed Feb 13, 2024
1 parent 0db7a24 commit bd590af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions client/wsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"sync"
Expand Down Expand Up @@ -136,6 +137,7 @@ func (c *wsClient) tryConnectOnce(ctx context.Context) (err error, retryAfter sh
// very liberal handling of 3xx that largely ignores HTTP semantics
redirect, err := resp.Location()
if err != nil {
fmt.Println("error in location", err)
c.common.Logger.Errorf(ctx, "%d redirect, but no valid location: %s", resp.StatusCode, err)
return err, duration
}
Expand All @@ -148,6 +150,9 @@ func (c *wsClient) tryConnectOnce(ctx context.Context) (err error, retryAfter sh
// Set the URL to the redirect, so that it connects to it on the
// next cycle.
c.url = redirect

// don't delay in following the redirect
duration = sharedinternal.ZeroDuration
} else {
c.common.Logger.Errorf(ctx, "Server responded with status=%v", resp.Status)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/retryafter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ type OptionalDuration struct {
Defined bool
}

// ZeroDuration represents a zero length duration that is defined.
var ZeroDuration = OptionalDuration{
Duration: 0,
Defined: true,
}

func parseDelaySeconds(s string) (time.Duration, error) {
n, err := strconv.Atoi(s)

Expand Down

0 comments on commit bd590af

Please sign in to comment.