Skip to content

HTTP2: Determine how to expose HTTP2 protocol error codes #26932

Closed
dotnet/corefx
#37223

Description

@geoffkizer

HTTP2 defines a list of protocol-level errors. Currently there is a Http2ProtocolErrorCode enum that defines these error codes, and Http2ProtocolException that exposes this enum. However, these aren't public currently; they get mapped into a generic HttpRequestException.

We need to determine if and how we want to expose these errors.

This is related to the broader question of how to expose more detailed error information about HTTP failures (is there an issue for this?). We may want to be consistent across HTTP/1.1 and HTTP2 here.

Activity

  1. davidsh commented on Jul 24, 2018

    @davidsh
    Contributor

    This is related to the broader question of how to expose more detailed error information about HTTP failures (is there an issue for this?). We may want to be consistent across HTTP/1.1 and HTTP2 here.

    We have several issues on this topic about adding more detailed, platform-independent, error information.

    #15567
    #21447
    #911

    In particular, the current thought I have is to extended HttpRequestException with a property that is similar to WebException.Status and an enum similar to WebExceptionStatus

  2. changed the title [-]HTTP: Determine how to expose HTTP2 protocol error codes[/-] [+]HTTP2: Determine how to expose HTTP2 protocol error codes[/+] on Jul 25, 2018
  3. rmkerr commented on Jul 31, 2018

    @rmkerr
    Contributor

    I'm actually running into several test failures where the private Http2ProtocolException is thrown without being wrapped in an HttpRequestException.

    For example, if I send a frame before the server connection preface:

    Assert.Throws() Failure
            Expected: typeof(System.Net.Http.HttpRequestException)
            Actual:   typeof(System.Net.Http.Http2Connection+Http2ProtocolException): Http2 Protocol Error, errorCode = ProtocolError
            Stack Trace:
               C:\corefx\src\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\Http2Connection.cs(96,0): at System.Net.Http.Http2Connection.SetupAsync()
               C:\corefx\src\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\HttpConnectionPool.cs(382,0): at System.Net.Http.HttpConnectionPool.GetHttp2ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
               E:\A\_work\41\s\src\System.Private.CoreLib\shared\System\Threading\Tasks\ValueTask.cs(849,0): at System.Threading.Tasks.ValueTask`1.get_Result()
               C:\corefx\src\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\HttpConnectionPool.cs(456,0): at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
               C:\corefx\src\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\RedirectHandler.cs(33,0): at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
               C:\corefx\src\System.Net.Http\src\System\Net\Http\HttpClient.cs(475,0): at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
               C:\corefx\src\System.Net.Http\tests\FunctionalTests\SocketsHttpHandlerTest.Http2.cs(62,0): at System.Net.Http.Functional.Tests.SocketsHttpHandler_HttpClientHandler_Http2_Test.<>c__DisplayClass3_0.<<Http2_DataSentBeforeServerPreface_ProtocolError>b__0>d.MoveNext()
    
  4. rmkerr commented on Jul 31, 2018

    @rmkerr
    Contributor

    In other similar situations I'm seeing an IOException, e.g., when the server closes the stream associated with a request before sending a response:

    Assert.Throws() Failure
            Expected: typeof(System.Net.Http.HttpRequestException)
            Actual:   typeof(System.IO.IOException): The server returned an invalid or unrecognized response.
            Stack Trace:
               C:\corefx\src\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\Http2Connection.cs(974,0): at System.Net.Http.Http2Connection.Http2Stream.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
               C:\corefx\src\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\Http2Connection.cs(688,0): at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
               C:\corefx\src\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\HttpConnectionPool.cs(467,0): at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
               C:\corefx\src\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\RedirectHandler.cs(33,0): at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
               C:\corefx\src\System.Net.Http\src\System\Net\Http\HttpClient.cs(475,0): at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
               C:\corefx\src\System.Net.Http\tests\FunctionalTests\SocketsHttpHandlerTest.Http2.cs(95,0): at System.Net.Http.Functional.Tests.SocketsHttpHandler_HttpClientHandler_Http2_Test.<>c__DisplayClass4_0.<<Http2_StreamResetByServer_RequestFails>b__0>d.MoveNext()
    
  5. geoffkizer commented on Jul 31, 2018

    @geoffkizer
    ContributorAuthor

    Yeah, there seems to be a missing try/catch to wrap these. We should only be exposing HttpRequestException.

  6. karelz commented on Apr 25, 2019

    @karelz
    Member

    @stephentoub we could use help with this one - at least design proposal. Thanks!

  7. stephentoub commented on Apr 25, 2019

    @stephentoub
    Member

    @davidsh, re: https://github.com/dotnet/corefx/issues/31315#issuecomment-407454597, are we on track to do anything about the 1.1 exception error codes / enums for .NET Core 3.0, or is that post-3.0?

  8. davidsh commented on Apr 25, 2019

    @davidsh
    Contributor

    @davidsh, re: dotnet/corefx#31315 (comment), are we on track to do anything about the 1.1 exception error codes / enums for .NET Core 3.0, or is that post-3.0?

    At this point, that larger set of issues is post-3.0.

    I don't think we need to expose the internal Http2ProtocolException class publicly:
    https://github.com/dotnet/corefx/blob/b176a73bdeb9bf3c79b63cee2f13da9a0e0759ab/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs#L1465-#L1466

    But I think we need to make sure it is an inner exception all the time we throw HttpRequestException for example. We can also derive this exception from Win32Exception instead of Exception. That allows us to put in the integer Http2ProtocolError. We should also make sure that the .Message property of this exception is an informative string.

    The key thing here is being able diagnose errors. As long as the inner exception has good information that is sufficient. We don't need to make this exception type a public type.

  9. stephentoub commented on Apr 25, 2019

    @stephentoub
    Member

    At this point, that larger set of issues is post-3.0.

    Ok, then I'll refrain from making this public now, too, as I'd want the public surface area to all be designed thoughtfully together. For now, I'll do something along the lines of what you suggest.

  10. self-assigned this
    on Apr 26, 2019
  11. transferred this issue fromdotnet/corefxon Jan 31, 2020
  12. added this to the 3.0 milestone on Jan 31, 2020
  13. ghost locked as resolved and limited conversation to collaborators on Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions