Repository navigation
Closed
Description
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
[-][HTTP/3] Graceful server shutdown and REJECT_REQUEST[/-][+][HTTP/3] Graceful server shutdown and H3_REQUEST_REJECTED[/+]wfurt commentedon Aug 6, 2021
we should perhaps also do interop with other clients and servers. (and of course look at the spec)
geoffkizer commentedon Aug 6, 2021
@ManickaP has code to support this, but it's not in yet. We were talking about this recently. See #56831
ManickaP commentedon Aug 6, 2021
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.
ManickaP commentedon Aug 6, 2021
Triage: since this is mostly mitigated by #56831 and we decided to punt the rest of the work, moving to future.
geoffkizer commentedon Aug 19, 2021
I'm moving this to 7.0 because I think we need to do something here for 7.0.
geoffkizer commentedon Aug 19, 2021
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.
JamesNK commentedon Aug 19, 2021
https://datatracker.ietf.org/doc/html/draft-ietf-quic-http-28#section-8.1
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.
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.
geoffkizer commentedon Aug 19, 2021
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.
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.
geoffkizer commentedon Aug 19, 2021
In fact, reading the RFC again, it calls out one specific case where H3_REQUEST_REJECTED could be used in non-shutdown cases:
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.
karelz commentedon Nov 16, 2021
Triage: We should drive design in 7.0 -- what we want to do. Then decide if it can be punted as rare race condition.
karelz commentedon Jun 14, 2022
Might be addressed by @rzikm's changes.