client.go | 22 +++++++++++++--------- peerconn.go | 5 ++++- requesting.go | 16 ++++++++-------- diff --git a/client.go b/client.go index af18b6d0604187cee61aa0652ff4b10b92acd3a8..179031d03e3a81b7b1bd21151a1769a05f9eb141 100644 --- a/client.go +++ b/client.go @@ -957,21 +957,25 @@ } defer t.dropConnection(c) c.startWriter() cl.sendInitialMessages(c, t) - c.updateRequestsTimer = time.AfterFunc(math.MaxInt64, func() { - if c.needRequestUpdate != "" { - return - } - if c.actualRequestState.Requests.IsEmpty() { - panic("updateRequestsTimer should have been stopped") - } - c.updateRequests("updateRequestsTimer") - }) + c.updateRequestsTimer = time.AfterFunc(math.MaxInt64, c.updateRequestsTimerFunc) c.updateRequestsTimer.Stop() err := c.mainReadLoop() if err != nil { return fmt.Errorf("main read loop: %w", err) } return nil +} + +func (c *PeerConn) updateRequestsTimerFunc() { + c.locker().Lock() + defer c.locker().Unlock() + if c.needRequestUpdate != "" { + return + } + if c.actualRequestState.Requests.IsEmpty() { + panic("updateRequestsTimer should have been stopped") + } + c.updateRequests("updateRequestsTimer") } // Maximum pending requests we allow peers to send us. If peer requests are buffered on read, this diff --git a/peerconn.go b/peerconn.go index 545e29f1faff716e11c640ef57c623a647641e05..36c070447d020e9fee85ab02c43bb8cc017ddbd4 100644 --- a/peerconn.go +++ b/peerconn.go @@ -1084,7 +1084,10 @@ }) if preservedCount != 0 { // TODO: Yes this is a debug log but I'm not happy with the state of the logging lib // right now. - log.Printf("%v requests were preserved while being choked", preservedCount) + log.Printf( + "%v requests were preserved while being choked (fast=%v)", + preservedCount, + c.fastEnabled()) torrent.Add("requestsPreservedThroughChoking", int64(preservedCount)) } c.updateRequests("unchoked") diff --git a/requesting.go b/requesting.go index 7d0c8f2fb3b8b75897a46cd37ddcac5550b6f30e..b551a48f79bd375c1fc76139239d040ad5b1800a 100644 --- a/requesting.go +++ b/requesting.go @@ -273,11 +273,12 @@ // requests, so we can skip this one with no additional consideration. return true } if maxRequests(current.Requests.GetCardinality()) >= p.nominalMaxRequests() { - log.Printf("not assigning all requests [desired=%v, cancelled=%v, max=%v]", - next.Requests.GetCardinality(), - p.cancelledRequests.GetCardinality(), - p.nominalMaxRequests(), - ) + //log.Printf("not assigning all requests [desired=%v, cancelled=%v, current=%v, max=%v]", + // next.Requests.GetCardinality(), + // p.cancelledRequests.GetCardinality(), + // current.Requests.GetCardinality(), + // p.nominalMaxRequests(), + //) return false } var err error @@ -287,11 +288,10 @@ panic(err) } return more }) + p.updateRequestsTimer.Stop() if more { p.needRequestUpdate = "" - if current.Requests.IsEmpty() { - p.updateRequestsTimer.Stop() - } else { + if !current.Requests.IsEmpty() { p.updateRequestsTimer.Reset(time.Second) } }