Skip to content

Commit

Permalink
set close state before unregisterStream
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels committed Aug 15, 2024
1 parent fae4852 commit e607601
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions association.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
22 changes: 22 additions & 0 deletions association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit e607601

Please sign in to comment.