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
bfc3909f
Unverified
Commit
bfc3909f
authored
Aug 21, 2019
by
Steven Allen
Committed by
GitHub
Aug 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #136 from libp2p/fix/listen-addrs-race
fix listen addrs race
parents
221d8d5e
682bcc86
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
swarm_addr.go
swarm_addr.go
+3
-3
swarm_addr_test.go
swarm_addr_test.go
+18
-0
No files found.
swarm_addr.go
View file @
bfc3909f
...
...
@@ -35,8 +35,8 @@ func (s *Swarm) InterfaceListenAddresses() ([]ma.Multiaddr, error) {
s
.
listeners
.
RUnlock
()
// RLock end
if
ifaceListenAddres
!=
nil
&&
!
isEOL
{
// Cache is valid
return
ifaceListenAddres
,
nil
// Cache is valid
, clone the slice
return
append
(
ifaceListenAddres
[
:
0
:
0
],
ifaceListenAddres
...
)
,
nil
}
// Cache is not valid
...
...
@@ -64,5 +64,5 @@ func (s *Swarm) InterfaceListenAddresses() ([]ma.Multiaddr, error) {
s
.
listeners
.
Unlock
()
// Lock end
return
ifaceListenAddres
,
nil
return
append
(
ifaceListenAddres
[
:
0
:
0
],
ifaceListenAddres
...
)
,
nil
}
swarm_addr_test.go
View file @
bfc3909f
...
...
@@ -35,3 +35,21 @@ func TestDialBadAddrs(t *testing.T) {
test
(
m
(
"/ip6/fe80::100"
))
// link local
test
(
m
(
"/ip4/127.0.0.1/udp/1234/utp"
))
// utp
}
func
TestAddrRace
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
s
:=
makeSwarms
(
ctx
,
t
,
1
)[
0
]
a1
,
err
:=
s
.
InterfaceListenAddresses
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
a2
,
err
:=
s
.
InterfaceListenAddresses
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
a1
)
>
0
&&
len
(
a2
)
>
0
&&
&
a1
[
0
]
==
&
a2
[
0
]
{
t
.
Fatal
(
"got the exact same address set twice; this could lead to data races"
)
}
}
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