-
Notifications
You must be signed in to change notification settings - Fork 43
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
Mid-stream error semantics? #895
Comments
This is out of scope for the HTTP core effort -- it would be considered a new feature. However, see this draft and resulting list discussion. After a discussion at our last interim, it seems like there's interest in discussing this general area (not only for caching, but also other purposes, potentially), but it still needs "time to bake." Probably the best way to move things forward is to participate in discussion on-list. Having more use cases fleshed out beyond caching will help to scope the work. |
Regarding HTTP/3, the concerns and solutions were discussed in quicwg/base-drafts#3300. |
Gotcha. I’ll probably post on the mailing list once I collect my thoughts with a more complete proposal, but for the moment I really want to know what I should do in an CTE stream to tell requesters that the response should be considered questionably-cacheable/damaged/non-authoritative/other stuff that 5XX errors get by default. |
The problem
I have a website that uses HTTP/1.1 chunked transfer-encoding to incrementally show results from asynchronous backend API calls in a streamed HTML response. This response routes through an NGiNX reverse-proxy, a CDN, and then an unknown number of gateways, middleboxes, and inspectors (like antivirus programs) before reaching the requesting user-agent.
Sometimes, a backend API call fails: the server’s connection to it closes unexpectedly, the backend emits an error of its own, or any other of the myriad ways computers and networks attack. By that time, I’ve already sent an HTTP status code and headers, but I really want the ability to tell any consuming clients that the stream encountered an error and the response should now be considered invalid, otherwise:
Research/prior art
No mid-stream error signaling possible, meaning prematurely-terminated responses are indistinguishable from the normal request termination of closing the connection. This limitation presumably informed future requirements on bodies requiring either a
content-length
ortransfer-encoding: chunked
length indicators.If a chunked response doesn’t terminate with the zero-length end chunk, the client must assume that the response was incomplete — which at the very least, means a cache should double-check with the server before reusing the stored incomplete response. There are two ways to emit such an incomplete response:
connection
and associated information are assumed to be hop-by-hop. Additionally, this can have undesirable performance implications when proxying through gateways by tearing down warmed-up persistent connections, and it precludes adding HTTP-level debugging info in trailers, which seem the natural place to include it.transfer-encoding
framing, such as missing or incorrect hex-encoded chunk lengths. Middleboxes also understandably will truncate or attempt to repair such invalid responses, resulting in the user-agent running into the aforementioned problems.An HTTP/2 stream can signal an application error by sending a
RST_STREAM
frame with an error code of0x2 INTERNAL_ERROR
… I think.I would love to not have to think about SPDY at all, but many CDNs and similar gateways will transparently downgrade to SPDY for older user-agents. Luckily, SPDY’s semantics more or less map to HTTP/2’s: see IETF draft: SPDY Protocol §2.4.2. Stream error handling; but the hex code for
INTERNAL_ERROR
might be0x6
insteadHTTP/3 §8 Error Handling seems to leave exact implementation open for experimentation, which is good overall but makes it harder for me to understand a recommendation for my case. “H3_INTERNAL_ERROR (0x0102)” seems ideal, but the error happening somewhere “in the HTTP stack” makes me wonder if it’s suitable for application-level use?
So what?
Persisting mid-stream application errors through various HTTP versions seems like something core HTTP semantics should allow for.
Guidance on how to signal mid-stream errors is hard to find, and I could only find guidance on translating those signals from HTTP/2 to HTTP/3. This is exacerbated by reverse proxies usually not bothering with supporting upstream connections higher than HTTP/1.1.
Existing methods to signal mid-stream errors can easily cause performance problems or unexpected behavior when attempting to convey them all the way to the requester.
While it’s theoretically possible to propagate 1 bit of error information (“is this response bad and shouldn’t be reused?”), other HTTP-level error data, such as
retry-after
, seem valuable to reuse.The text was updated successfully, but these errors were encountered: