Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
213edd7c
Commit
213edd7c
authored
Jul 31, 2019
by
Dirk McCormick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: memory leak in latency tracker on timeout after cancel
parent
5204f405
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
sessionpeermanager/sessionpeermanager.go
sessionpeermanager/sessionpeermanager.go
+6
-1
sessionpeermanager/sessionpeermanager_test.go
sessionpeermanager/sessionpeermanager_test.go
+6
-0
No files found.
sessionpeermanager/sessionpeermanager.go
View file @
213edd7c
...
...
@@ -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
)
}
}
...
...
sessionpeermanager/sessionpeermanager_test.go
View file @
213edd7c
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment