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

HttpProtocolException is not reported properly on initial HTTP/2 settings handshake failure #82168

Closed
antonfirsov opened this issue Feb 15, 2023 · 2 comments · Fixed by #88974

Comments

@antonfirsov
Copy link
Member

antonfirsov commented Feb 15, 2023

There is an overlook in #71345. When the server doesn't initiate the connection with a proper SETTINGS preface, eg. responding by GOAWAY instead, the InnerException of the HttpRequestException being thrown must be a ProtocolException according to #70684.

Instead, we embed ProtocolException into further IOException-s 2 levels down in ProcessIncomingFramesAsync().

Repro:

[ConditionalFact(nameof(SupportsAlpn))]
public async Task Test()
{
    using Http2LoopbackServer server = Http2LoopbackServer.CreateServer();
    using HttpClient client = CreateHttpClient();
            
    Task<HttpResponseMessage> sendTask = client.GetAsync(server.Address);

    Http2LoopbackConnection connection = await server.AcceptConnectionAsync();
    await connection.ReadSettingsAsync();
    await connection.SendGoAway(0, ProtocolErrors.INTERNAL_ERROR);

    var ex = await Assert.ThrowsAsync<HttpRequestException>(() => sendTask);
    Assert.IsType<HttpProtocolException>(ex.InnerException); // Fails
}
@ghost
Copy link

ghost commented Feb 15, 2023

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

There is an overlook in #71345. When the server doesn't initiate the connection with a proper SETTINGS preface, eg. responding by GOAWAY instead, the InnerException of the HttpRequestException being thrown must be a ProtocolException according to #70684.

Instead, we embed ProtocolException into further IOException-s 2 levels down in ProcessIncomingFramesAsync().

Repro:

[ConditionalFact(nameof(SupportsAlpn))]
public async Task Test()
{
    using Http2LoopbackServer server = Http2LoopbackServer.CreateServer();
    using HttpClient client = CreateHttpClient();
            
    Task<HttpResponseMessage> sendTask = client.GetAsync(server.Address);

    Http2LoopbackConnection connection = await server.AcceptConnectionAsync();
    await connection.ReadSettingsAsync();
    await connection.SendGoAway(0, ProtocolErrors.INTERNAL_ERROR);

    var ex = await Assert.ThrowsAsync<HttpRequestException>(() => sendTask);
    Assert.IsType<HttpProtocolException>(ex.InnerException);
}
Author: antonfirsov
Assignees: -
Labels:

area-System.Net.Http

Milestone: -

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 15, 2023
@MihaZupan MihaZupan added the bug label Feb 15, 2023
@CarnaViire
Copy link
Member

Triage: this looks like something straightforward to fix. We should fix it in 8.0.

@CarnaViire CarnaViire added this to the 8.0.0 milestone Mar 14, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Mar 14, 2023
@karelz karelz modified the milestones: 8.0.0, Future Jun 13, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 17, 2023
@karelz karelz modified the milestones: Future, 9.0.0 Jul 18, 2023
antonfirsov added a commit that referenced this issue Jul 18, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 18, 2023
@karelz karelz modified the milestones: 9.0.0, 8.0.0 Aug 1, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants