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-dms3
Commits
aa70bbaf
Commit
aa70bbaf
authored
Oct 19, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
evil deadlock that wasn't.
important to always reread your code.
parent
29ab6dec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
6 deletions
+10
-6
net/swarm/conn.go
net/swarm/conn.go
+4
-5
net/swarm/simul_test.go
net/swarm/simul_test.go
+4
-1
net/swarm/swarm_test.go
net/swarm/swarm_test.go
+2
-0
No files found.
net/swarm/conn.go
View file @
aa70bbaf
...
...
@@ -102,8 +102,8 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
// add to conns
s
.
connsLock
.
Lock
()
mc
,
ok
:=
s
.
conns
[
c
.
RemotePeer
()
.
Key
()]
if
!
ok
{
mc
,
found
:=
s
.
conns
[
c
.
RemotePeer
()
.
Key
()]
if
!
found
{
// multiconn doesn't exist, make a new one.
conns
:=
[]
conn
.
Conn
{
c
}
mc
,
err
:=
conn
.
NewMultiConn
(
s
.
Context
(),
s
.
local
,
c
.
RemotePeer
(),
conns
)
...
...
@@ -116,6 +116,8 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
s
.
conns
[
c
.
RemotePeer
()
.
Key
()]
=
mc
s
.
connsLock
.
Unlock
()
// kick off reader goroutine
go
s
.
fanInSingle
(
mc
)
log
.
Debug
(
"added new multiconn: %s"
,
mc
)
}
else
{
s
.
connsLock
.
Unlock
()
// unlock before adding new conn
...
...
@@ -125,9 +127,6 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
}
log
.
Debug
(
"multiconn added new conn %s"
,
c
)
// kick off reader goroutine
go
s
.
fanInSingle
(
c
)
return
c
,
nil
}
...
...
net/swarm/simul_test.go
View file @
aa70bbaf
...
...
@@ -61,8 +61,11 @@ func TestSimultOpenMany(t *testing.T) {
}
func
TestSimultOpenFewStress
(
t
*
testing
.
T
)
{
// t.Skip("skipping for another test")
for
i
:=
0
;
i
<
100
;
i
++
{
num
:=
10
// num := 100
for
i
:=
0
;
i
<
num
;
i
++
{
addrs
:=
[]
string
{
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/%d"
,
1900
+
i
),
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/%d"
,
2900
+
i
),
...
...
net/swarm/swarm_test.go
View file @
aa70bbaf
...
...
@@ -141,6 +141,7 @@ func SubtestSwarm(t *testing.T, addrs []string, MsgNum int) {
got
:=
map
[
u
.
Key
]
int
{}
for
k
:=
0
;
k
<
(
MsgNum
*
len
(
*
peers
));
k
++
{
log
.
Debug
(
"%s waiting for pong (%d)"
,
s1
.
local
,
k
)
msg
:=
<-
s1
.
Incoming
if
string
(
msg
.
Data
())
!=
"pong"
{
t
.
Error
(
"unexpected conn output"
,
msg
.
Data
)
...
...
@@ -180,6 +181,7 @@ func TestSwarm(t *testing.T) {
"/ip4/127.0.0.1/tcp/1238"
,
}
// msgs := 1000
msgs
:=
100
SubtestSwarm
(
t
,
addrs
,
msgs
)
}
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