fix edge case on ticker

This commit is contained in:
Lucca Martins 2025-02-25 16:51:27 -03:00
parent 844603ea4e
commit a7e3222023
No known key found for this signature in database
GPG key ID: DC3D7F76BDAE23BF

View file

@ -33,6 +33,7 @@ var (
const ( const (
heimdallAPIBodyLimit = 128 * 1024 * 1024 // 128 MB heimdallAPIBodyLimit = 128 * 1024 * 1024 // 128 MB
stateFetchLimit = 50 stateFetchLimit = 50
retryCall = 5 * time.Second
) )
type StateSyncEventsResponse struct { type StateSyncEventsResponse struct {
@ -292,7 +293,13 @@ func FetchWithRetry[T any](ctx context.Context, client http.Client, url *url.URL
log.Warn("an error while trying fetching from Heimdall", "path", url.Path, "attempt", attempt, "error", err) log.Warn("an error while trying fetching from Heimdall", "path", url.Path, "attempt", attempt, "error", err)
// create a new ticker for retrying the request // create a new ticker for retrying the request
ticker := time.NewTicker(client.Timeout) var ticker *time.Ticker
if client.Timeout != 0 {
ticker = time.NewTicker(client.Timeout)
} else {
// only reach here when HeimdallClient is HeimdallGRPCClient or HeimdallAppClient
ticker = time.NewTicker(retryCall)
}
defer ticker.Stop() defer ticker.Stop()
const logEach = 5 const logEach = 5