Skip to content

[HTTP/3] Graceful server shutdown and H3_REQUEST_REJECTED #56944

Closed

Description

@JamesNK

If a server is gracefully shutting down it will send a GOAWAY and then abort incoming requests with the status code H3_REQUEST_REJECTED. These are requests that could have been sent before HttpClient receives the GOAWAY.

What I see:

  Message: 
System.Net.Http.HttpRequestException : An error occurred while sending the request.
---- System.Net.Quic.QuicStreamAbortedException : Stream aborted by peer (267).

  Stack Trace: 
Http3RequestStream.SendAsync(CancellationToken cancellationToken)
Http3RequestStream.SendAsync(CancellationToken cancellationToken)
Http3Connection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpConnectionPool.TrySendUsingHttp3Async(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
HttpConnectionPool.DetermineVersionAndSendAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
HttpConnectionPool.SendAndProcessAltSvcAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
Http3RequestTests.ConnectionLifetimeNotificationFeature_RequestClose_ConnectionEnds() line 825
--- End of stack trace from previous location ---
----- Inner Stack Trace -----
MsQuicStream.HandleEventPeerSendAborted(State state, StreamEvent& evt)
MsQuicStream.HandleEvent(State state, StreamEvent& evt)
MsQuicStream.NativeCallbackHandler(IntPtr stream, IntPtr context, StreamEvent& streamEvent)
--- End of stack trace from previous location ---
ResettableCompletionSource`1.GetResult(Int16 token)
Http3RequestStream.ReadFrameEnvelopeAsync(CancellationToken cancellationToken)
Http3RequestStream.ReadResponseAsync(CancellationToken cancellationToken)
Http3RequestStream.SendAsync(CancellationToken cancellationToken)

I haven't looked closely at client behavior in the spec, but I would have thought that HttpClient would resend rejected requests on a new connection.

Activity

  1. ghost added
    untriaged
    on Aug 6, 2021
  2. changed the title [-][HTTP/3] Graceful server shutdown and REJECT_REQUEST[/-] [+][HTTP/3] Graceful server shutdown and H3_REQUEST_REJECTED[/+] on Aug 6, 2021
  3. wfurt commented on Aug 6, 2021

    @wfurt
    Member

    we should perhaps also do interop with other clients and servers. (and of course look at the spec)

  4. geoffkizer commented on Aug 6, 2021

    @geoffkizer
    Contributor

    @ManickaP has code to support this, but it's not in yet. We were talking about this recently. See #56831

  5. ManickaP commented on Aug 6, 2021

    @ManickaP
    Member

    Yes, this should be mostly mitigated with my PR. However, as we discussed, since there's a race between GoAway (on the control stream) and the request itself, we might be too fast with retrying the request on the same connection. It's captured in #56870 and I think that implementing multiple connection support #51775 might help fixing this as well.

  6. ManickaP commented on Aug 6, 2021

    @ManickaP
    Member

    Triage: since this is mostly mitigated by #56831 and we decided to punt the rest of the work, moving to future.

  7. removed
    untriaged
    on Aug 6, 2021
  8. added this to the Future milestone on Aug 6, 2021
  9. modified the milestones: Future, 7.0.0 on Aug 19, 2021
  10. geoffkizer commented on Aug 19, 2021

    @geoffkizer
    Contributor

    I'm moving this to 7.0 because I think we need to do something here for 7.0.

  11. geoffkizer commented on Aug 19, 2021

    @geoffkizer
    Contributor

    One option here would be to assume that receiving H3_REQUEST_REJECTED means that the server is in the process of shutting down, and has (or will promptly) send us a GOAWAY, but we just haven't seen it yet. So, we would just treat this as if we did receive a GOAWAY (though without a last stream ID specified), and begin the process of shutting down the connection and creating a new one (if necessary). When we eventually receive the GOAWAY with a real last stream ID, we can then process it and retry requests beyond the specified last stream ID.

    This assumes that the only reason a server would send H3_REQUEST_REJECTED is because it is shutting down. From reading the RFC, it doesn't explicitly say this, but it seems like a reasonable assumption to make.

    If that's not a reasonable assumption, then things get more complicated. I guess we would need to wait for a brief period of time after receiving the H3_REQUEST_REJECTED to see if we actually get a GOAWAY or not. If we do, then we start shutting down the connection and retry this request on a new connection. But if the timeout expires, we retry on the same connection. That seems kinda complicated, but I'm not sure what else to do.

  12. JamesNK commented on Aug 19, 2021

    @JamesNK
    MemberAuthor

    https://datatracker.ietf.org/doc/html/draft-ietf-quic-http-28#section-8.1

    H3_REQUEST_REJECTED (0x10B): A server rejected a request without
    performing any application processing.

    This is a pretty generic description. IMO it is too big an assumption to start shutting down a connection if this status is returned.

    I could imagine someone writes server connection middleware that limits the number of active requests and rejects requests over a limit. It would be a valid abort code to use because the server rejected the request prior to processing.

    If that's not a reasonable assumption, then things get more complicated. I guess we would need to wait for a brief period of time after receiving the H3_REQUEST_REJECTED to see if we actually get a GOAWAY or not. If we do, then we start shutting down the connection and retry this request on a new connection. But if the timeout expires, we retry on the same connection. That seems kinda complicated, but I'm not sure what else to do.

    This was my first thought about how it could be handled.

    An idea for another option for handling this in the client: the client could immediately retry the rejected requests on the same connection if GOAWAY hasn't been received yet. If the GOAWAY is received afterwards then the newly retried request will be aborted again (both by the client, and the server), and retried on a new connection. A thing to watch out for would be limiting the number of times the same request is retried. Maybe just retry once. You don't want to get into a loop.

  13. geoffkizer commented on Aug 19, 2021

    @geoffkizer
    Contributor

    This is a pretty generic description. IMO it is too big an assumption to start shutting down a connection if this status is returned.

    Yeah, I agree, it seems kinda questionable to make this assumption.

    I wish there was an error code that specifically meant "rejected because server is shutting down" but there isn't, and assuming that H3_REQUEST_REJECTED always means that is probably not reasonable.

    I also wish there was some sort of guidance in the RFC around how to retry a request after H3_REQUEST_REJECTED; without this, the fact that you can retry it is less useful.

    Maybe it's worth engaging the working group on this.

    An idea for another option for handling this in the client: the client could immediately retry the rejected requests on the same connection if GOAWAY hasn't been received yet. If the GOAWAY is received afterwards then the newly retried request will be aborted again (both by the client, and the server), and retried on a new connection. A thing to watch out for would be limiting the number of times the same request is retried. Maybe just retry once. You don't want to get into a loop.

    This is in fact what we do today (as of #56831). I believe the retry limit is 3 times. Unfortunately, this still results in unreliable behavior because in rare cases we will still exceed the retry limit before processing the GOAWAY.

    Given the state of the RFC, I guess we will have to live with some level of unreliability here, but it would be nice to make this reliable enough that we can re-enable the tests that depend on this.

  14. geoffkizer commented on Aug 19, 2021

    @geoffkizer
    Contributor

    In fact, reading the RFC again, it calls out one specific case where H3_REQUEST_REJECTED could be used in non-shutdown cases:

    For example, an intermediary that receives an HTTP/2
       stream error of type REFUSED_STREAM from the origin has a clear
       signal that the request was not processed and that the request is
       safe to retry.  Propagating this error condition to the client as an
       HTTP/3 stream error of type H3_REQUEST_REJECTED allows the client to
       take the action it deems most appropriate.  In the reverse direction
       the intermediary might deem it beneficial to pass on client request
       cancellations that are indicated by terminating a stream with
       H3_REQUEST_CANCELLED.
    

    https://datatracker.ietf.org/doc/html/draft-ietf-quic-http-28#appendix-A.4.1

    In this case it seems like the correct thing to do would be to immediately retry the request on the same connection and let the intermediary determine what downstream connection to route it to.

    Given this, I am not sure exactly what a client is supposed to do when receiving H3_REQUEST_REJECTED without receiving GOAWAY first. Seems like there is no behavior that does the correct thing in all cases.

  15. karelz commented on Nov 16, 2021

    @karelz
    Member

    Triage: We should drive design in 7.0 -- what we want to do. Then decide if it can be punted as rare race condition.

  16. karelz commented on Jun 14, 2022

    @karelz
    Member

    Might be addressed by @rzikm's changes.

  17. ghost added
    in-pr
    on Jul 15, 2022
  18. ghost removed
    in-pr
    on Jul 15, 2022
  19. ghost locked as resolved and limited conversation to collaborators on Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions