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
p2p
go-p2p-swarm
Commits
9b27a665
Unverified
Commit
9b27a665
authored
Jan 23, 2019
by
Steven Allen
Committed by
GitHub
Jan 23, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #95 from libp2p/fix/avoid-useless-goroutines
avoid spawning goroutines for canceled dials
parents
f056f38c
49805313
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
limiter.go
limiter.go
+22
-6
No files found.
limiter.go
View file @
9b27a665
...
...
@@ -77,17 +77,26 @@ func newDialLimiterWithParams(df dialfunc, fdLimit, perPeerLimit int) *dialLimit
func
(
dl
*
dialLimiter
)
freeFDToken
()
{
dl
.
fdConsuming
--
i
f
len
(
dl
.
waitingOnFd
)
>
0
{
f
or
len
(
dl
.
waitingOnFd
)
>
0
{
next
:=
dl
.
waitingOnFd
[
0
]
dl
.
waitingOnFd
[
0
]
=
nil
// clear out memory
dl
.
waitingOnFd
=
dl
.
waitingOnFd
[
1
:
]
if
len
(
dl
.
waitingOnFd
)
==
0
{
dl
.
waitingOnFd
=
nil
// clear out memory
// clear out memory.
dl
.
waitingOnFd
=
nil
}
// Skip over canceled dials instead of queuing up a goroutine.
if
next
.
cancelled
()
{
dl
.
freePeerToken
(
next
)
continue
}
dl
.
fdConsuming
++
// we already have activePerPeer token at this point so we can just dial
go
dl
.
executeDial
(
next
)
return
}
}
...
...
@@ -99,18 +108,25 @@ func (dl *dialLimiter) freePeerToken(dj *dialJob) {
}
waitlist
:=
dl
.
waitingOnPeerLimit
[
dj
.
peer
]
i
f
len
(
waitlist
)
>
0
{
f
or
len
(
waitlist
)
>
0
{
next
:=
waitlist
[
0
]
if
len
(
waitlist
)
==
1
{
waitlist
[
0
]
=
nil
// clear out memory
waitlist
=
waitlist
[
1
:
]
if
len
(
waitlist
)
==
0
{
delete
(
dl
.
waitingOnPeerLimit
,
next
.
peer
)
}
else
{
waitlist
[
0
]
=
nil
// clear out memory
dl
.
waitingOnPeerLimit
[
next
.
peer
]
=
waitlist
[
1
:
]
dl
.
waitingOnPeerLimit
[
next
.
peer
]
=
waitlist
}
if
next
.
cancelled
()
{
continue
}
dl
.
activePerPeer
[
next
.
peer
]
++
// just kidding, we still want this token
dl
.
addCheckFdLimit
(
next
)
return
}
}
...
...
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