Skip to content

Commit

Permalink
bitswap/httpnet: handle special 500 error case
Browse files Browse the repository at this point in the history
  • Loading branch information
hsanjuan committed Feb 20, 2025
1 parent 791468b commit adb7a63
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions bitswap/network/httpnet/msg_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm
http.StatusUnavailableForLegalReasons:

err := fmt.Errorf("%s %q -> %d: %q", req.Method, req.URL, resp.StatusCode, string(body))
log.Error(err)
log.Debug(err)
// clear cooldowns since we got a proper reply
if !u.cooldown.Load().(time.Time).IsZero() {
sender.ht.cooldownTracker.remove(req.URL.Host)
Expand Down Expand Up @@ -365,6 +365,19 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm
Err: err,
}

case http.StatusInternalServerError:
// special handling because of error seen in the wild
// because some implementation does it this way
if string(body) == "ipld: could not find node" {
err := fmt.Errorf("treating as 404: %q -> %d: %q", req.URL, resp.StatusCode, string(body))
log.Warn(err)
return nil, &senderError{
Type: typeClient,
Err: err,
}
}
fallthrough // otherwise assume error

// For any other code, we assume we must temporally
// backoff from the URL per the options.
// Tolerance for server errors per url is low. If after waiting etc.
Expand Down Expand Up @@ -496,7 +509,7 @@ WANTLIST_LOOP:
// error handling
switch result.err.Type {
case typeFatal:
log.Errorf("Disconnecting from %s: %w", sender.peer, result.err.Err)
log.Errorf("Disconnecting from %s: %s", sender.peer, result.err.Err)
sender.ht.DisconnectFrom(ctx, sender.peer)
err = result.err
// continue processing responses as workers
Expand Down

0 comments on commit adb7a63

Please sign in to comment.