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 18c4015
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 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,11 @@ func (a *Association) OpenStream(streamIdentifier uint16, defaultPayloadType Pay
a.lock.Lock()
defer a.lock.Unlock()

switch a.getState() {
case shutdownAckSent, shutdownPending, shutdownReceived, shutdownSent, 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 18c4015

Please sign in to comment.