Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set close state before unregisterStream #350

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
Loading