1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 19:24:14 +08:00

evil deadlock that wasn't.

important to always reread your code.
This commit is contained in:
Juan Batiz-Benet
2014-10-19 06:21:06 -07:00
parent 29ab6dec60
commit aa70bbaf15
3 changed files with 10 additions and 6 deletions

View File

@ -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
}

View File

@ -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),

View File

@ -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)
}