client.go | 4 +++- peerconn.go | 10 +++++++++- torrent.go | 9 +++++++++ diff --git a/client.go b/client.go index e36ec0e980834516cd0a34c338c879389da864f5..7586fa80c1f887b15eb0f0193a55aba039f92eeb 100644 --- a/client.go +++ b/client.go @@ -1000,7 +1000,9 @@ // If there are no outstanding requests, then a request update should have already run. 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 fb28dc2275b3388c45ae1c25e66d68652c67e565..c71581ac592fe8c22d297c96f8455364585cc357 100644 --- a/peerconn.go +++ b/peerconn.go @@ -1030,6 +1030,7 @@ } else { 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 @@ // 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 2e6fb6ef9e1115ca2b55082677cca1520477d23e..fbb5f6b005256dbbee547b9d987117ee6cebd8a1 100644 --- a/torrent.go +++ b/torrent.go @@ -2381,3 +2381,12 @@ 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 +}