Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #164 from dirkmc/fix/latency-tracker-memory-leak
Browse files Browse the repository at this point in the history
fix: memory leak in latency tracker on timeout after cancel
  • Loading branch information
Stebalien authored Aug 1, 2019
2 parents 1137add + 213edd7 commit f62bf54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sessionpeermanager/sessionpeermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,12 @@ type peerTimeoutMessage struct {

func (ptm *peerTimeoutMessage) handle(spm *SessionPeerManager) {
data, ok := spm.activePeers[ptm.p]
if !ok || !data.lt.WasCancelled(ptm.k) {
// If the request was cancelled, make sure we clean up the request tracker
if ok && data.lt.WasCancelled(ptm.k) {
data.lt.RemoveRequest(ptm.k)
} else {
// If the request was not cancelled, record the latency. Note that we
// do this even if we didn't previously know about this peer.
spm.recordResponse(ptm.p, ptm.k)
}
}
Expand Down
6 changes: 6 additions & 0 deletions sessionpeermanager/sessionpeermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,18 @@ func TestTimeoutsAndCancels(t *testing.T) {
sessionPeerManager.RecordCancel(c4[0])
time.Sleep(2 * time.Millisecond)
sessionPeerManager.RecordPeerResponse(peer2, c4[0])
time.Sleep(2 * time.Millisecond)

// call again
fourthSessionPeers := sessionPeerManager.GetOptimizedPeers()
if thirdSessionPeers[1].OptimizationRating >= fourthSessionPeers[1].OptimizationRating {
t.Fatal("Timeout should have affected optimization rating but did not")
}

// ensure all peer latency tracking has been cleaned up
if len(sessionPeerManager.activePeers[peer2].lt.requests) > 0 {
t.Fatal("Latency request tracking should have been cleaned up but was not")
}
}

func TestUntaggingPeers(t *testing.T) {
Expand Down

0 comments on commit f62bf54

Please sign in to comment.