Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public void Cleanup()
// inbound.
internal MsQuicStream(MsQuicConnection.State connectionState, SafeMsQuicStreamHandle streamHandle, QUIC_STREAM_OPEN_FLAGS flags)
{
if (!connectionState.TryAddStream(this))
{
throw new ObjectDisposedException(nameof(QuicConnection));
}
// this assignment should be done before SetCallbackHandlerDelegate to prevent NRE in HandleEventConnectionClose
// but after TryAddStream to prevent unnecessary RemoveStream in finalizer
_state.ConnectionState = connectionState;

_state.Handle = streamHandle;
_canRead = true;
_canWrite = !flags.HasFlag(QUIC_STREAM_OPEN_FLAGS.UNIDIRECTIONAL);
Expand All @@ -117,14 +125,6 @@ internal MsQuicStream(MsQuicConnection.State connectionState, SafeMsQuicStreamHa
throw;
}

if (!connectionState.TryAddStream(this))
{
_state.StateGCHandle.Free();
throw new ObjectDisposedException(nameof(QuicConnection));
}

_state.ConnectionState = connectionState;

_state.TraceId = MsQuicTraceHelper.GetTraceId(_state.Handle);
if (NetEventSource.Log.IsEnabled())
{
Expand All @@ -140,6 +140,14 @@ internal MsQuicStream(MsQuicConnection.State connectionState, QUIC_STREAM_OPEN_F
{
Debug.Assert(connectionState.Handle != null);

if (!connectionState.TryAddStream(this))
{
throw new ObjectDisposedException(nameof(QuicConnection));
}
// this assignment should be done before StreamOpenDelegate to prevent NRE in HandleEventConnectionClose
// but after TryAddStream to prevent unnecessary RemoveStream in finalizer
_state.ConnectionState = connectionState;

_canRead = !flags.HasFlag(QUIC_STREAM_OPEN_FLAGS.UNIDIRECTIONAL);
_canWrite = true;

Expand Down Expand Up @@ -170,15 +178,6 @@ internal MsQuicStream(MsQuicConnection.State connectionState, QUIC_STREAM_OPEN_F
throw;
}

if (!connectionState.TryAddStream(this))
{
_state.Handle?.Dispose();
_state.StateGCHandle.Free();
throw new ObjectDisposedException(nameof(QuicConnection));
}

_state.ConnectionState = connectionState;

_state.TraceId = MsQuicTraceHelper.GetTraceId(_state.Handle);
if (NetEventSource.Log.IsEnabled())
{
Expand Down