Skip to content

Commit

Permalink
fix: deadlock on panic in transport testsuite
Browse files Browse the repository at this point in the history
I had a panic in `list.Multiaddr()` which would deadlock the test instead of properly showing up the stack trace.

This happens because in the defer block it waits for <-done however because the test never proceed the other goroutine is stuck on `.Accept()`, never sending `close(done)`.
  • Loading branch information
Jorropo committed Aug 22, 2024
1 parent 412daa4 commit d9247c2
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions p2p/transport/testsuite/transport_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,17 @@ func SubtestBasic(t *testing.T, ta, tb transport.Transport, maddr ma.Multiaddr,
}
defer list.Close()

var (
connA, connB transport.CapableConn
done = make(chan struct{})
)
defer func() {
<-done
if connA != nil {
connA.Close()
}
if connB != nil {
connB.Close()
}
}()
done := make(chan struct{})

go func() {
defer close(done)
var err error
connB, err = list.Accept()
connB, err := list.Accept()
if err != nil {
t.Error(err)
return
}
defer connB.Close()

s, err := connB.AcceptStream()
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -115,10 +104,11 @@ func SubtestBasic(t *testing.T, ta, tb transport.Transport, maddr ma.Multiaddr,
t.Error("CanDial should have returned true")
}

connA, err = tb.Dial(ctx, list.Multiaddr(), peerA)
connA, err := tb.Dial(ctx, list.Multiaddr(), peerA)
if err != nil {
t.Fatal(err)
}
defer connA.Close()

s, err := connA.OpenStream(context.Background())
if err != nil {
Expand Down Expand Up @@ -154,6 +144,8 @@ func SubtestBasic(t *testing.T, ta, tb transport.Transport, maddr ma.Multiaddr,
t.Fatal(err)
return
}

<-done
}

func SubtestPingPong(t *testing.T, ta, tb transport.Transport, maddr ma.Multiaddr, peerA peer.ID) {
Expand Down

0 comments on commit d9247c2

Please sign in to comment.