From e607601de51ea4b4ec299f8fbbc871d27a6d5585 Mon Sep 17 00:00:00 2001 From: Eric Daniels Date: Wed, 14 Aug 2024 18:35:51 -0400 Subject: [PATCH] set close state before unregisterStream --- association.go | 1 + association_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/association.go b/association.go index 5be88389..29e9978c 100644 --- a/association.go +++ b/association.go @@ -573,6 +573,7 @@ func (a *Association) readLoop() { a.closeWriteLoopOnce.Do(func() { close(a.closeWriteLoopCh) }) a.lock.Lock() + a.setState(closed) for _, s := range a.streams { a.unregisterStream(s, closeErr) } diff --git a/association_test.go b/association_test.go index 1a512149..141daa1e 100644 --- a/association_test.go +++ b/association_test.go @@ -3475,3 +3475,25 @@ func TestAssociation_OpenStreamAfterClose(t *testing.T) { _, err = a2.OpenStream(1, PayloadTypeWebRTCString) require.ErrorIs(t, err, ErrAssociationClosed) } + +// https://github.com/pion/sctp/pull/350 +// may need to run with a high test count to reproduce if there +// is ever a regression. +func TestAssociation_OpenStreamAfterInternalClose(t *testing.T) { + checkGoroutineLeaks(t) + + a1, a2, err := createAssocs() + require.NoError(t, err) + + a1.netConn.Close() + a2.netConn.Close() + + a1.OpenStream(1, PayloadTypeWebRTCString) + a2.OpenStream(1, PayloadTypeWebRTCString) + + require.NoError(t, a1.Close()) + require.NoError(t, a2.Close()) + + require.Equal(t, 0, len(a1.streams)) + require.Equal(t, 0, len(a2.streams)) +}