Skip to content

Commit

Permalink
Do not add streams after association is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels committed Aug 12, 2024
1 parent 15d9422 commit 3365bd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions association.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
ErrChunk = errors.New("abort chunk, with following errors")
ErrShutdownNonEstablished = errors.New("shutdown called in non-established state")
ErrAssociationClosedBeforeConn = errors.New("association closed before connecting")
ErrAssociationClosed = errors.New("association closed")
ErrSilentlyDiscard = errors.New("silently discard")
ErrInitNotStoredToSend = errors.New("the init not stored to send")
ErrCookieEchoNotStoredToSend = errors.New("cookieEcho not stored to send")
Expand Down Expand Up @@ -1505,6 +1506,10 @@ func (a *Association) OpenStream(streamIdentifier uint16, defaultPayloadType Pay
a.lock.Lock()
defer a.lock.Unlock()

if a.getState() == closed {
return nil, ErrAssociationClosed
}

return a.getOrCreateStream(streamIdentifier, false, defaultPayloadType), nil
}

Expand Down
16 changes: 16 additions & 0 deletions association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3455,3 +3455,19 @@ func TestAssociation_ReconfigRequestsLimited(t *testing.T) {
require.NoError(t, a1.Close())
require.NoError(t, a2.Close())
}

func TestAssociation_OpenStreamAfterClose(t *testing.T) {
checkGoroutineLeaks(t)

a1, a2, err := createAssocs()
require.NoError(t, err)

require.NoError(t, a1.Close())
require.NoError(t, a2.Close())

_, err = a1.OpenStream(1, PayloadTypeWebRTCString)
require.ErrorIs(t, err, ErrAssociationClosed)

_, err = a2.OpenStream(1, PayloadTypeWebRTCString)
require.ErrorIs(t, err, ErrAssociationClosed)
}

0 comments on commit 3365bd4

Please sign in to comment.