Skip to content

Commit 58f27d8

Browse files
authored
polygon: Add Cloudflare transient err (#13731)
Polygon node crashed with the following error ``` [EROR] [02-06|09:17:35.922] polygon sync crashed - stopping node err="pos sync heimdall failed: span scraper failed: can't fetch id range: error while fetching data from Heimdall: url='https://heimdall-api-amoy.polygon.technology/bor/latest-span', status=404, body='<!DOCTYPE html>\n<html>\n\n<head>\n <title>Error ・ Cloudflare Access</title> ``` This should not be a failing error as it is likely due to Cloudflare masking downtime of the Heimdall endpoint that are currently covered by `ErrServiceUnavailable`. We specifically check for `404` status codes as other status codes like `403` may signal other errors such as Cloudflare's DDoS protection.
1 parent 8818242 commit 58f27d8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

polygon/heimdall/client_http.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"net/http"
2626
"net/url"
2727
"path"
28+
"regexp"
2829
"sort"
2930
"strconv"
3031
"strings"
@@ -45,10 +46,12 @@ var (
4546
ErrNotInCheckpointList = errors.New("checkpontId doesn't exist in Heimdall")
4647
ErrBadGateway = errors.New("bad gateway")
4748
ErrServiceUnavailable = errors.New("service unavailable")
49+
ErrCloudflareAccess = errors.New("cloudflare access")
4850

4951
TransientErrors = []error{
5052
ErrBadGateway,
5153
ErrServiceUnavailable,
54+
ErrCloudflareAccess,
5255
context.DeadlineExceeded,
5356
}
5457
)
@@ -661,7 +664,13 @@ func internalFetch(ctx context.Context, handler httpRequestHandler, u *url.URL,
661664

662665
// check status code
663666
if res.StatusCode != 200 {
664-
return nil, fmt.Errorf("%w: url='%s', status=%d, body='%s'", ErrNotSuccessfulResponse, u.String(), res.StatusCode, string(body))
667+
cloudflareErr := regexp.MustCompile(`Error.*Cloudflare Access`)
668+
bodyStr := string(body)
669+
if res.StatusCode == 404 && cloudflareErr.MatchString(bodyStr) {
670+
return nil, fmt.Errorf("%w: url='%s', status=%d, body='%s'", ErrCloudflareAccess, u.String(), res.StatusCode, bodyStr)
671+
}
672+
673+
return nil, fmt.Errorf("%w: url='%s', status=%d, body='%s'", ErrNotSuccessfulResponse, u.String(), res.StatusCode, bodyStr)
665674
}
666675

667676
return body, nil

0 commit comments

Comments
 (0)