evil deadlock that wasn't.
important to always reread your code.
Juan Batiz-Benet committed
Oct 19, 2014 at 06:21 UTC
aa70bbaf15067d7c02149581ca7236f52cd2b22d
3 files changed
+10
-6
net/swarm/conn.go
+4
-5
@@ -102,8 +102,8 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
102
// add to conns
103
s.connsLock.Lock()
104
105
- mc, ok := s.conns[c.RemotePeer().Key()]
106
- if !ok {
105
+ mc, found := s.conns[c.RemotePeer().Key()]
106
+ if !found {
107
// multiconn doesn't exist, make a new one.
108
conns := []conn.Conn{c}
109
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) {
116
s.conns[c.RemotePeer().Key()] = mc
117
s.connsLock.Unlock()
118
119
+ // kick off reader goroutine
120
+ go s.fanInSingle(mc)
121
log.Debug("added new multiconn: %s", mc)
122
} else {
123
s.connsLock.Unlock() // unlock before adding new conn
@@ -125,9 +127,6 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
127
}
128
129
log.Debug("multiconn added new conn %s", c)
128
-
129
- // kick off reader goroutine
130
- go s.fanInSingle(c)
130
return c, nil
131
}
132
net/swarm/simul_test.go
+4
-1
@@ -61,8 +61,11 @@ func TestSimultOpenMany(t *testing.T) {
61
}
62
63
func TestSimultOpenFewStress(t *testing.T) {
64
+ // t.Skip("skipping for another test")
65
65
- for i := 0; i < 100; i++ {
66
+ num := 10
67
+ // num := 100
68
+ for i := 0; i < num; i++ {
69
addrs := []string{
70
fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", 1900+i),
71
fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", 2900+i),
net/swarm/swarm_test.go
+2
@@ -141,6 +141,7 @@ func SubtestSwarm(t *testing.T, addrs []string, MsgNum int) {
141
142
got := map[u.Key]int{}
143
for k := 0; k < (MsgNum * len(*peers)); k++ {
144
+ log.Debug("%s waiting for pong (%d)", s1.local, k)
145
msg := <-s1.Incoming
146
if string(msg.Data()) != "pong" {
147
t.Error("unexpected conn output", msg.Data)
@@ -180,6 +181,7 @@ func TestSwarm(t *testing.T) {
181
"/ip4/127.0.0.1/tcp/1238",
182
}
183
184
+ // msgs := 1000
185
msgs := 100
186
SubtestSwarm(t, addrs, msgs)
187
}