diff --git a/client.go b/client.go index e36ec0e9..7586fa80 100644 --- a/client.go +++ b/client.go @@ -1000,7 +1000,9 @@ func (c *Peer) updateRequestsTimerFunc() { return } if d := time.Since(c.lastRequestUpdate); d < updateRequestsTimerDuration { - log.Printf("spurious timer requests update [interval=%v]", d) + // These should be benign, Timer.Stop doesn't guarantee that its function won't run if it's + // already been fired. + torrent.Add("spurious timer requests updates", 1) return } c.updateRequests(peerUpdateRequestsTimerReason) diff --git a/peerconn.go b/peerconn.go index fb28dc22..c71581ac 100644 --- a/peerconn.go +++ b/peerconn.go @@ -1030,6 +1030,7 @@ func (c *PeerConn) peerRequestDataReader(r Request, prs *peerRequestState) { if b == nil { panic("data must be non-nil to trigger send") } + torrent.Add("peer request data read successes", 1) prs.data = b c.tickleWriter() } @@ -1038,7 +1039,14 @@ func (c *PeerConn) peerRequestDataReader(r Request, prs *peerRequestState) { // If this is maintained correctly, we might be able to support optional synchronous reading for // chunk sending, the way it used to work. func (c *PeerConn) peerRequestDataReadFailed(err error, r Request) { - c.logger.WithDefaultLevel(log.Warning).Printf("error reading chunk for peer Request %v: %v", r, err) + torrent.Add("peer request data read failures", 1) + logLevel := log.Warning + if c.t.hasStorageCap() { + // It's expected that pieces might drop. See + // https://github.com/anacrolix/torrent/issues/702#issuecomment-1000953313. + logLevel = log.Debug + } + c.logger.WithDefaultLevel(logLevel).Printf("error reading chunk for peer Request %v: %v", r, err) if c.t.closed.IsSet() { return } diff --git a/torrent.go b/torrent.go index 2e6fb6ef..fbb5f6b0 100644 --- a/torrent.go +++ b/torrent.go @@ -2381,3 +2381,12 @@ func (t *Torrent) deleteConnWithAllPieces(p *Peer) bool { func (t *Torrent) numActivePeers() int { return len(t.conns) + len(t.webSeeds) } + +func (t *Torrent) hasStorageCap() bool { + f := t.storage.Capacity + if f == nil { + return false + } + _, ok := (*f)() + return ok +}