Skip to content

Commit

Permalink
Log retries in NodeRPC client (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
vegarsti authored Jun 27, 2024
1 parent f51a38f commit efd4e3c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion client/jsonrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,21 @@ func NewClient(log *slog.Logger, cfg Config) (*rpcClient, error) { // revive:dis
client := retryablehttp.NewClient()
client.RetryMax = MaxRetries
client.Logger = log
client.CheckRetry = retryablehttp.DefaultRetryPolicy
checkRetry := func(ctx context.Context, resp *http.Response, err error) (bool, error) {
yes, err2 := retryablehttp.DefaultRetryPolicy(ctx, resp, err)
if yes {
if resp == nil {
log.Warn("Retrying request", "error", err)
} else {
log.Warn("Retrying request", "statusCode", resp.Status, "error", err)
}
}
return yes, err2
}
client.CheckRetry = checkRetry
client.Backoff = retryablehttp.LinearJitterBackoff
client.HTTPClient.Timeout = DefaultRequestTimeout

rpc := &rpcClient{
client: client,
cfg: cfg,
Expand Down

0 comments on commit efd4e3c

Please sign in to comment.