]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add webseed error counter and reduce error log level
authorMatt Joiner <anacrolix@gmail.com>
Wed, 4 Jun 2025 00:39:56 +0000 (10:39 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 4 Jun 2025 00:56:09 +0000 (10:56 +1000)
client.go
webseed-peer.go
webseed-request.go

index dbe0b31ea6452e310ca232fadaf58ac2e59e437f..74d5d7e1c21b03a52aff48504163e10c7d868b98 100644 (file)
--- a/client.go
+++ b/client.go
@@ -274,6 +274,7 @@ func (cl *Client) init(cfg *ClientConfig) {
                }
        }
        cl.defaultLocalLtepProtocolMap = makeBuiltinLtepProtocols(!cfg.DisablePEX)
+       g.MakeMap(&cl.numWebSeedRequests)
 }
 
 // Creates a new Client. Takes ownership of the ClientConfig. Create another one if you want another
index f02845a44e8ae45595b322f790a6b9bfbb11913b..d08f982185e94478fd83d363d98f3f2b85df0ee7 100644 (file)
@@ -97,7 +97,7 @@ func (ws *webseedPeer) writeInterested(interested bool) bool {
 
 func (ws *webseedPeer) handleCancel(r RequestIndex) {
        for wr := range ws.activeRequestsForIndex(r) {
-               wr.request.Cancel()
+               wr.Cancel()
        }
 }
 
@@ -152,13 +152,14 @@ func (ws *webseedPeer) runRequest(webseedRequest *webseedRequest) {
        locker := ws.locker
        err := ws.readChunks(webseedRequest)
        // Ensure the body reader and response are closed.
-       webseedRequest.request.Cancel()
+       webseedRequest.Close()
        if err != nil {
-               level := slog.LevelWarn
-               if errors.Is(err, context.Canceled) {
+               level := slog.LevelInfo
+               if webseedRequest.cancelled {
                        level = slog.LevelDebug
                }
                ws.slogger().Log(context.TODO(), level, "webseed request error", "err", err)
+               torrent.Add("webseed request error count", 1)
                // This used to occur only on webseed.ErrTooFast but I think it makes sense to slow down any
                // kind of error. Pausing here will starve the available requester slots which slows things
                // down.
index 0f8440dbe3d5bdad3f4b2e567f3be04a4ceb9c5f..7e601d6b00cce199c3ff15b3d3a2a13c9848ef99 100644 (file)
@@ -6,11 +6,23 @@ import (
 
 // A wrapper around webseed.Request with extra state for webseedPeer.
 type webseedRequest struct {
+       // Fingers out.
        request webseed.Request
        // First assigned in the range.
        begin RequestIndex
        // The next to be read.
        next RequestIndex
        // One greater than the end of the range.
-       end RequestIndex
+       end       RequestIndex
+       cancelled bool
+}
+
+func (me *webseedRequest) Close() {
+       me.request.Cancel()
+}
+
+// Record that it was exceptionally cancelled.
+func (me *webseedRequest) Cancel() {
+       me.cancelled = true
+       me.request.Cancel()
 }