Skip to content

Commit

Permalink
Fix Wrong exception for Open*Stream after connection is closed (#67342)
Browse files Browse the repository at this point in the history
* Fix Wrong exception for Open*Stream after connection is closed

* Don't handle InvalidState

* Update src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/MsQuicStream.cs

Co-authored-by: Natalia Kondratyeva <knatalia@microsoft.com>

Co-authored-by: Natalia Kondratyeva <knatalia@microsoft.com>
  • Loading branch information
rzikm and CarnaViire authored Mar 31, 2022
1 parent fe0f600 commit a847ddf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ internal MsQuicStream(MsQuicConnection.State connectionState, QUIC_STREAM_OPEN_F
GCHandle.ToIntPtr(_state.StateGCHandle),
out _state.Handle);

if (status == MsQuicStatusCodes.Aborted)
{
// connection already aborted by peer, throw relevant exception
throw ThrowHelper.GetConnectionAbortedException(connectionState.AbortErrorCode);
}

QuicExceptionHelpers.ThrowIfFailed(status, "Failed to open stream to peer.");

Debug.Assert(!Monitor.IsEntered(_state), "!Monitor.IsEntered(_state)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ await RunClientServer(
else
{
await Assert.ThrowsAsync<QuicOperationAbortedException>(async () => await serverConnection.AcceptStreamAsync());

// TODO: ActiveIssue https://github.com/dotnet/runtime/issues/56133
// MsQuic fails with System.Net.Quic.QuicException: Failed to open stream to peer. Error Code: INVALID_STATE
//await Assert.ThrowsAsync<QuicOperationAbortedException>(async () => await OpenAndUseStreamAsync(serverConnection));
await Assert.ThrowsAsync<QuicException>(() => OpenAndUseStreamAsync(serverConnection));
}
});
Expand Down Expand Up @@ -166,17 +162,8 @@ await RunClientServer(
// Subsequent attempts should fail
ex = await Assert.ThrowsAsync<QuicConnectionAbortedException>(() => serverConnection.AcceptStreamAsync().AsTask());
Assert.Equal(ExpectedErrorCode, ex.ErrorCode);
// TODO: ActiveIssue https://github.com/dotnet/runtime/issues/56133
// MsQuic fails with System.Net.Quic.QuicException: Failed to open stream to peer. Error Code: INVALID_STATE
if (IsMsQuicProvider)
{
await Assert.ThrowsAsync<QuicException>(() => OpenAndUseStreamAsync(serverConnection));
}
else
{
ex = await Assert.ThrowsAsync<QuicConnectionAbortedException>(() => OpenAndUseStreamAsync(serverConnection));
Assert.Equal(ExpectedErrorCode, ex.ErrorCode);
}
ex = await Assert.ThrowsAsync<QuicConnectionAbortedException>(() => OpenAndUseStreamAsync(serverConnection));
Assert.Equal(ExpectedErrorCode, ex.ErrorCode);
});
}

Expand Down

0 comments on commit a847ddf

Please sign in to comment.