mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-04 13:27:14 +08:00
evil deadlock that wasn't.
important to always reread your code.
This commit is contained in:
@ -102,8 +102,8 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
|
|||||||
// add to conns
|
// add to conns
|
||||||
s.connsLock.Lock()
|
s.connsLock.Lock()
|
||||||
|
|
||||||
mc, ok := s.conns[c.RemotePeer().Key()]
|
mc, found := s.conns[c.RemotePeer().Key()]
|
||||||
if !ok {
|
if !found {
|
||||||
// multiconn doesn't exist, make a new one.
|
// multiconn doesn't exist, make a new one.
|
||||||
conns := []conn.Conn{c}
|
conns := []conn.Conn{c}
|
||||||
mc, err := conn.NewMultiConn(s.Context(), s.local, c.RemotePeer(), conns)
|
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.conns[c.RemotePeer().Key()] = mc
|
||||||
s.connsLock.Unlock()
|
s.connsLock.Unlock()
|
||||||
|
|
||||||
|
// kick off reader goroutine
|
||||||
|
go s.fanInSingle(mc)
|
||||||
log.Debug("added new multiconn: %s", mc)
|
log.Debug("added new multiconn: %s", mc)
|
||||||
} else {
|
} else {
|
||||||
s.connsLock.Unlock() // unlock before adding new conn
|
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)
|
log.Debug("multiconn added new conn %s", c)
|
||||||
|
|
||||||
// kick off reader goroutine
|
|
||||||
go s.fanInSingle(c)
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +61,11 @@ func TestSimultOpenMany(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSimultOpenFewStress(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{
|
addrs := []string{
|
||||||
fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", 1900+i),
|
fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", 1900+i),
|
||||||
fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", 2900+i),
|
fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", 2900+i),
|
||||||
|
@ -141,6 +141,7 @@ func SubtestSwarm(t *testing.T, addrs []string, MsgNum int) {
|
|||||||
|
|
||||||
got := map[u.Key]int{}
|
got := map[u.Key]int{}
|
||||||
for k := 0; k < (MsgNum * len(*peers)); k++ {
|
for k := 0; k < (MsgNum * len(*peers)); k++ {
|
||||||
|
log.Debug("%s waiting for pong (%d)", s1.local, k)
|
||||||
msg := <-s1.Incoming
|
msg := <-s1.Incoming
|
||||||
if string(msg.Data()) != "pong" {
|
if string(msg.Data()) != "pong" {
|
||||||
t.Error("unexpected conn output", msg.Data)
|
t.Error("unexpected conn output", msg.Data)
|
||||||
@ -180,6 +181,7 @@ func TestSwarm(t *testing.T) {
|
|||||||
"/ip4/127.0.0.1/tcp/1238",
|
"/ip4/127.0.0.1/tcp/1238",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// msgs := 1000
|
||||||
msgs := 100
|
msgs := 100
|
||||||
SubtestSwarm(t, addrs, msgs)
|
SubtestSwarm(t, addrs, msgs)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user