Skip to content

Commit

Permalink
fix races
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed Jul 15, 2024
1 parent 5eae18f commit ee2c60a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions peerconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ another:
// Hard to say what to return here.
return true
}
more := c.sendChunk(peerRequest.Request, msg, peerRequest.state)
more := c.sendChunk(peerRequest.Request, msg, peerRequest.state, lock)

func() {
if lock {
Expand Down Expand Up @@ -1271,8 +1271,14 @@ func (c *PeerConn) tickleWriter() {
c.messageWriter.writeCond.Broadcast()
}

func (c *PeerConn) sendChunk(r Request, msg func(pp.Message, bool) bool, state *peerRequestState) (more bool) {
c.lastChunkSent = time.Now()
func (c *PeerConn) sendChunk(r Request, msg func(pp.Message, bool) bool, state *peerRequestState, lock bool) (more bool) {
func() {
if lock {
c.mu.Lock()
defer c.mu.Unlock()
}
c.lastChunkSent = time.Now()
}()
state.allocReservation.Release()
return msg(pp.Message{
Type: pp.Piece,
Expand Down

0 comments on commit ee2c60a

Please sign in to comment.