Skip to content

Commit

Permalink
Fix on nil pointer after connection broken with the Feeder gateway (#379
Browse files Browse the repository at this point in the history
)

Fix nil pointer error on logs after an error fetching from the feeder gateway
Remove 10 times and check for requests to the feeder gateway, will be forever.
  • Loading branch information
stdevMac committed Aug 31, 2022
1 parent a25cdfd commit d497805
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pkg/feeder/feeder.go
Expand Up @@ -54,14 +54,13 @@ func NewClient(baseURL, baseAPI string, client *HttpClient) *Client {
// retry mechanism for do requests
retryFuncForDoReq := func(req *http.Request, httpClient HttpClient) (*http.Response, error) {
var res *http.Response
wait := 5 * time.Second
for i := 0; i < 10; i++ {
wait := 2 * time.Second
for {
res, err = httpClient.Do(req)
if err != nil || res.StatusCode != http.StatusOK {
Logger.With("Error", err, "StatusCode", res.StatusCode).Debug("Error connecting to the gateway.")
Logger.With("Waiting:", wait.Seconds()).Info("Waiting to do again a request")
if err != nil || res == nil || res.StatusCode != http.StatusOK {
wait *= 2
Logger.With("Waiting:", wait.Seconds(), "Error", err).Info("Waiting to do again a request")
time.Sleep(wait)
wait = wait * 2
continue
}
if res.StatusCode == http.StatusOK {
Expand Down Expand Up @@ -197,7 +196,7 @@ func (c *Client) do(req *http.Request, v any) (*http.Response, error) {
// otherwise. de-Marshals response into appropriate ByteCode and ABI structs.
func (c *Client) doCodeWithABI(req *http.Request, v *CodeInfo) (*http.Response, error) {
metr.IncreaseABISent()
res, err := (*c.httpClient).Do(req)
res, err := c.retryFuncForDoReq(req, *c.httpClient)
if err != nil {
metr.IncreaseABIFailed()
return nil, err
Expand Down

0 comments on commit d497805

Please sign in to comment.