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 1 commit
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,15 @@ private async ValueTask SendDataAsync(ReadOnlyMemory<byte> buffer, CancellationT
await _connection.SendStreamDataAsync(StreamId, current, flush, _requestBodyCancellationSource.Token).ConfigureAwait(false);
}
}
catch (Exception)
alnikola marked this conversation as resolved.
Show resolved Hide resolved
{
if (_resetException is Exception resetException)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check and throw the exception the same way as CheckResponseBodyState does in:

if (_resetException is Exception resetException)
{
if (_canRetry)
{
ThrowRetry(SR.net_http_request_aborted, resetException);
}
ThrowRequestAborted(resetException);
}

ProcessGoAwayFrame sets _canRetry to true AFAICT and we're not handling it here.

Could we just directly call CheckResponseBodyState in the exception handling block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_canRetry check has been added, but we cannot call CheckResponseBodyState here because it asserts for a lock like this
Debug.Assert(Monitor.IsEntered(SyncObject));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just take the lock and call it, then?

CheckResponseBodyState also checks for _responseProtocolState == ResponseProtocolState.Aborted; should we be checking that here too?

Copy link
Contributor Author

@alnikola alnikola Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not check _responseProtocolState here because SendDataAsync is called to send request data, so I believe it should control request-related logic only. That's another reason why I think we shouldn't call CheckResponseBodyState here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geoffkizer Could you please check out my reply above?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, your comment sounds right to me.

{
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("HTTP/2 error code 'PROTOCOL_ERROR'", exception.InnerException.InnerException.Message);
alnikola marked this conversation as resolved.
Show resolved Hide resolved
}
}

[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