Improve error handling for bad webseeds
DNS "no such host" errors didn't interrupt the stream of outbound requests.
This commit is contained in:
parent
a90ae5aed4
commit
63b7215892
|
@ -4,8 +4,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/RoaringBitmap/roaring"
|
||||
|
@ -118,6 +116,7 @@ func (ws *webseedPeer) handleUpdateRequests() {
|
|||
|
||||
func (ws *webseedPeer) onClose() {
|
||||
ws.peer.logger.WithLevel(log.Debug).Print("closing")
|
||||
ws.peer.deleteAllRequests()
|
||||
for _, r := range ws.activeRequests {
|
||||
r.Cancel()
|
||||
}
|
||||
|
@ -134,25 +133,15 @@ func (ws *webseedPeer) requestResultHandler(r Request, webseedRequest webseed.Re
|
|||
ws.peer.t.cl.lock()
|
||||
defer ws.peer.t.cl.unlock()
|
||||
if result.Err != nil {
|
||||
if !errors.Is(result.Err, context.Canceled) {
|
||||
if !errors.Is(result.Err, context.Canceled) && !ws.peer.closed.IsSet() {
|
||||
ws.peer.logger.Printf("Request %v rejected: %v", r, result.Err)
|
||||
}
|
||||
// We need to filter out temporary errors, but this is a nightmare in Go. Currently a bad
|
||||
// webseed URL can starve out the good ones due to the chunk selection algorithm.
|
||||
const closeOnAllErrors = false
|
||||
if closeOnAllErrors ||
|
||||
strings.Contains(result.Err.Error(), "unsupported protocol scheme") ||
|
||||
func() bool {
|
||||
var err webseed.ErrBadResponse
|
||||
if !errors.As(result.Err, &err) {
|
||||
return false
|
||||
}
|
||||
return err.Response.StatusCode == http.StatusNotFound
|
||||
}() {
|
||||
// cfg := spew.NewDefaultConfig()
|
||||
// cfg.DisableMethods = true
|
||||
// cfg.Dump(result.Err)
|
||||
log.Printf("closing %v", ws)
|
||||
ws.peer.close()
|
||||
} else {
|
||||
ws.peer.remoteRejectedRequest(ws.peer.t.requestIndexFromRequest(r))
|
||||
}
|
||||
ws.peer.remoteRejectedRequest(ws.peer.t.requestIndexFromRequest(r))
|
||||
} else {
|
||||
err := ws.peer.receiveChunk(&pp.Message{
|
||||
Type: pp.Piece,
|
||||
|
|
Loading…
Reference in New Issue