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

Http2Stream throws a wrapped Http2ConnectionException on GO_AWAY #54625

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,23 @@ private async ValueTask SendDataAsync(ReadOnlyMemory<byte> buffer, CancellationT
await _connection.SendStreamDataAsync(StreamId, current, flush, _requestBodyCancellationSource.Token).ConfigureAwait(false);
}
}
catch (OperationCanceledException e) when (e.CancellationToken == _requestBodyCancellationSource.Token)
{
lock (SyncObject)
{
if (_resetException is Exception resetException)
{
if (_canRetry)
{
ThrowRetry(SR.net_http_request_aborted, resetException);
}

ThrowRequestAborted(resetException);
}
}

throw;
}
finally
{
linkedRegistration.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,39 @@ await Assert.ThrowsAnyAsync<HttpRequestException>(() =>
}
}

[ConditionalFact(nameof(SupportsAlpn))]
public async Task GoAwayFrame_RequestWithBody_ServerDisconnect_AbortStreamsAndThrowIOException()
{
using (Http2LoopbackServer server = Http2LoopbackServer.CreateServer())
using (HttpClient client = CreateHttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, server.Address);
request.Version = new Version(2, 0);
var content = new string('*', 300);
var stream = new CustomContent.SlowTestStream(Encoding.UTF8.GetBytes(content), null, count: 60);
request.Content = new CustomContent(stream);

Task<HttpResponseMessage> sendTask = client.SendAsync(request);

Http2LoopbackConnection connection = await server.EstablishConnectionAsync();
(int streamId, _) = await connection.ReadAndParseRequestHeaderAsync(readBody: false);
await connection.SendDefaultResponseHeadersAsync(streamId);

await connection.SendGoAway(0, errorCode: ProtocolErrors.PROTOCOL_ERROR);

// Expect client to detect that server has disconnected and throw an exception
var exception = await Assert.ThrowsAnyAsync<HttpRequestException>(() =>
new Task[]
{
sendTask
}.WhenAllOrAnyFailed(TestHelper.PassingTestTimeoutMilliseconds));

Assert.IsType<IOException>(exception.InnerException);
Assert.NotNull(exception.InnerException.InnerException);
Assert.Contains("PROTOCOL_ERROR", exception.InnerException.InnerException.Message);
}
}

[ConditionalFact(nameof(SupportsAlpn))]
public async Task GoAwayFrame_UnprocessedStreamFirstRequestFinishedFirst_RequestRestarted()
{
Expand Down Expand Up @@ -2790,8 +2823,8 @@ public async Task PostAsyncDuplex_ServerResetsStream_Throws()
// Trying to read on the response stream should fail now, and client should ignore any data received
await AssertProtocolErrorForIOExceptionAsync(SendAndReceiveResponseDataAsync(contentBytes, responseStream, connection, streamId), ProtocolErrors.ENHANCE_YOUR_CALM);

// Attempting to write on the request body should now fail with OperationCanceledException.
Exception e = await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => { await SendAndReceiveRequestDataAsync(contentBytes, requestStream, connection, streamId); });
// Attempting to write on the request body should now fail with IOException.
Exception e = await Assert.ThrowsAnyAsync<IOException>(async () => { await SendAndReceiveRequestDataAsync(contentBytes, requestStream, connection, streamId); });

// Propagate the exception to the request stream serialization task.
// This allows the request processing to complete.
Expand Down