Repository navigation
Description
Description:
When configured to proxy Expect: 100-continue (via proxy_100_continue), envoy will not forward timeouts to the client or update internal metrics as expected.
Config / Repro steps:
Don't have a clean minimal config to share, but I can reliably reproduce in a config where the listener has proxy_100_continue set to be true and the upstream cluster for a route has a timeout shorter than the request duration (with an upstream setup to support 100-continue itself)
From the perspective of curl, this looks like this:
> ....
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
* TLSv1.2 (IN), TLS alert, Client hello (1):
* Empty reply from server
* Connection #0 to host <url> left intact
curl: (52) Empty reply from server
This happens because in router.cc, onUpstream100ContinueHeaders sets downstream_response_started_ to be true. Then when the request times out, onUpstreamAbort destroys the stream instead of sending & updating the code.
Ideally the client would get the 503, but I'm not actually sure what is allowed/expected here as per http spec. What is definitely an issue is that we don't see expected timeout metrics for this (because chargeUpstreamAbort also checks downstream_response_started_), and not updating the response code internally means that in, eg access logs we see a status of 100 as supposed to a 503.
Logs:
Envoy debug logs when this happens:
2020-07-16 14:36:58.201 [44][debug][router] [source/common/router/router.cc:816] [C6487][S12773442203076911571] upstream timeout
2020-07-16 14:36:58.201 [44][debug][router] [source/common/router/upstream_request.cc:263] [C6487][S12773442203076911571] resetting pool request
2020-07-16 14:36:58.201 [44][debug][client] [source/common/http/codec_client.cc:114] [C6490] request reset
2020-07-16 14:36:58.201 [44][debug][connection] [source/common/network/connection_impl.cc:109] [C6490] closing data_to_write=0 type=1
2020-07-16 14:36:58.201 [44][debug][connection] [source/common/network/connection_impl.cc:200] [C6490] closing socket: 1
2020-07-16 14:36:58.201 [44][debug][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:298] [C6490] SSL shutdown: rc=0
2020-07-16 14:36:58.201 [44][debug][connection] [source/extensions/transport_sockets/tls/ssl_socket.cc:226] [C6490]
2020-07-16 14:36:58.202 [44][debug][client] [source/common/http/codec_client.cc:91] [C6490] disconnect. resetting 0 pending requests
2020-07-16 14:36:58.202 [44][debug][pool] [source/common/http/conn_pool_base.cc:265] [C6490] client disconnected, failure reason:
2020-07-16 14:36:58.202 [44][debug][http] [source/common/http/conn_manager_impl.cc:205] [C6487][S12773442203076911571] doEndStream() resetting stream
2020-07-16 14:36:58.202 [44][debug][http] [source/common/http/conn_manager_impl.cc:1936] [C6487][S12773442203076911571] stream reset
2020-07-16 14:36:58.202 [44][debug][connection] [source/common/network/connection_impl.cc:109] [C6487] closing data_to_write=0 type=2
2020-07-16 14:36:58.202 [44][debug][connection] [source/common/network/connection_impl_base.cc:30] [C6487] setting delayed close timer with timeout 1000 ms
2020-07-16 14:36:58.202 [44][debug][pool] [source/common/http/conn_pool_base.cc:93] [C6490] destroying stream: 0 remaining
Activity
[-]Envoy does not forward/recognize timeout response codes when proxying 100-continue[/-][+]Envoy doesn't forward/recognize timeout response codes when proxying 100-continue[/+]mattklein123 commentedon Jul 16, 2020
cc @alyssawilk
alyssawilk commentedon Jul 16, 2020
Hm, I think we should be willing to send informational headers if only informational headers have been sent, and I could imagine that being a bug. I'll take a look.
alyssawilk commentedon Jul 16, 2020
Incidentally, my guess is Envoy is just sending an H2 reset or an HTTP/1 connection close, as it would if there were a timeout during body processing. If that's the case it should be a straight-forward fix.
jcdavis commentedon Jul 16, 2020
@alyssawilk that is my understanding too. The root cause seems to be that the expectation of
downstream_response_started_is that the downstream has already received headers/etc and that is no longer safe to send a 503 status code, but of course100-continueis a wierd corner case where that behavior is not only allowed, but desiredalyssawilk commentedon Jul 16, 2020
Yeah, I think in the case of sending a reply, it's pretty easy to say if we've sent 1xx but not other response headers, we can send 5xx on upstream failure rather than just resetting the stream. More interesting is hedging and retries. I hate to penalize the upstream for sending early non-informational headers, but I am concerned about the complexity of allowing a retry which might send its own 1xx (we've had problems with more than 1 1xx). I'm inclined to at least have the first pass fix just be fixing the error communication and not the error handling.
jcdavis commentedon Jul 16, 2020
Sounds reasonable - I'm certainly not the expert on this :)
alyssawilk commentedon Jul 20, 2020
I've got a PR out for the error handling case. I think after @htuch 's work on 100 coalescing we could handle the retry case pretty easily too. If we coalesce in the HCM we can even handle redirects as well cc @penguingao
http: allowing 100 then 500 (#12185)
http: allowing 100 then 500 (envoyproxy#12185)
http: allowing 100 then 500 (envoyproxy#12185)