Skip to content

Commit

Permalink
defer delete for non errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed Dec 3, 2024
1 parent 54a75e7 commit e4e6b46
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions webseed-peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,6 @@ func (ws *webseedPeer) requestResultHandler(r Request, webseedRequest webseed.Re
result := <-webseedRequest.Result
close(webseedRequest.Result) // one-shot

// remove the request now to avoid adding unhandled cancels
ws.peer.mu.Lock()
delete(ws.activeRequests, r)
ws.peer.mu.Unlock()

defer func() {
for _, reader := range result.Readers {
reader.Close()
Expand Down Expand Up @@ -589,6 +584,11 @@ func (ws *webseedPeer) requestResultHandler(r Request, webseedRequest webseed.Re
}
}

// remove the request now to avoid adding unhandled cancels
ws.peer.mu.Lock()
delete(ws.activeRequests, r)
ws.peer.mu.Unlock()

if !ws.peer.remoteRejectedRequest(ws.peer.t.requestIndexFromRequest(r, true)) {
err = fmt.Errorf(`received invalid reject "%w", for request %v`, err, r)
ws.peer.logger.Levelf(log.Debug, "%v", err)
Expand All @@ -604,6 +604,10 @@ func (ws *webseedPeer) requestResultHandler(r Request, webseedRequest webseed.Re
Piece: piece,
})

ws.peer.mu.Lock()
delete(ws.activeRequests, r)
ws.peer.mu.Unlock()

if err != nil {
panic(err)
}
Expand Down

0 comments on commit e4e6b46

Please sign in to comment.