envoy icon indicating copy to clipboard operation
envoy copied to clipboard

Envoy intermittently responds with 503 UC (upstream_reset_before_response_started{connection_termination})

Open aqua777 opened this issue 5 years ago • 32 comments

Title: Envoy intermittently responds with 503 UC (upstream_reset_before_response_started{connection_termination})

Description:

What issue is being seen? Describe what should be happening instead of the bug, for example: Envoy should not crash, the expected value isn't returned, etc.

We have a group of Envoy servers running as an Edge Proxy for a number of backend services. We configure these Envoy servers using in-house built xDS GRPC server. See example configuration dump attached to this issue.

We started noticing intermittent responses with error code 503 and response flag "UC" + upstream_reset_before_response_started{connection_termination} appearing in response code details. It seems that these responses are produced by Envoy and not returned by the backend services. We observed this issue while running Envoy versions v1.16 and v1.17.

We looked at some previously reported similar GitHub issues, such as:

  • https://github.com/envoyproxy/envoy/issues/8639
  • https://github.com/istio/istio/issues/15285

We tried to change some configuration settings, namely:

  • enable TCP Keep-alives
  • adjust Idle Timeouts (for ex. use default values, disable idle timeout)

None of the actions mentioned above had any influence on the behavior of our Envoys' fleet.

Repro steps: We have no repeatable method for reproducing these errors. They are very sporadic, ie. 1-2 per 100000 requests. They are spread across various clusters. Some of these clusters receive large and constant amount of requests so the possibility of the upstream connections to become idle is very unlikely.

Config: See included in tarball attached to this issue

Logs: This issue occurs in our Production environment where we do not have debug level logging enabled.

Can you please advise:

  • why does the Envoy terminates connections?
  • have this problem been reported by other Envoy's users?
  • is there a possibility that requests are not distributed evenly across all backend servers which could lead to Envoy resetting upstream connections?
  • what can we do on our side to eliminate this problem?

aqua777 avatar Feb 08 '21 16:02 aqua777

cc @alyssawilk

One possible explanation for this class of problems may be that the upstream server closes the connection as the proxy starts sending the request. It may be helpful to know how long the upstream connection was open prior to the first request being sent on it.

antoniovicente avatar Feb 08 '21 19:02 antoniovicente

cc @alyssawilk

One possible explanation for this class of problems may be that the upstream server closes the connection as the proxy starts sending the request. It may be helpful to know how long the upstream connection was open prior to the first request being sent on it.

Thanks for possible explanation. We were considering this and there are factors that are against this assumption. Prior to using Envoys our load balancing were based on hardware Load Balancers. With hardware LBs we haven't seen such behavior, ie. connection terminations by backend servers. After switching to Envoys we started seeing behavior described in this issue across multiple clusters, large and small, using different webservers, serving various amount of requests, all kinds of differences.

aqua777 avatar Feb 08 '21 21:02 aqua777

The error code indicates that it not Envoy that terminated the connection but rather the upstream server (or intervening network infrastructure). Did you look at the counters? For instance any of the upstream_cx_... error counters corresponding to disconnects?

yanavlasov avatar Feb 09 '21 02:02 yanavlasov

@yanavlasov thank you for suggestion. In our infrastructure we have some restrictions in how many metrics we can send to Prometheus servers so we had to configure Envoy to use inclusion patterns for metrics. upstream_cx_destroy... metrics are not on that list, we will add them and will provide more details shortly.

aqua777 avatar Feb 09 '21 08:02 aqua777

We've managed to capture one of the requests resulting in 503 response code, see the output below:

[2021-02-09 14:23:14.220][24][debug][conn_handler] [source/server/connection_handler_impl.cc:501] [C1876] new connection
[2021-02-09 14:23:14.222][24][debug][http] [source/common/http/conn_manager_impl.cc:254] [C1876] new stream
[2021-02-09 14:23:14.222][24][debug][http] [source/common/http/conn_manager_impl.cc:886] [C1876][S15748738241223205728] request headers complete (end_stream=true):
':authority', '...'
':path', '/...'
':method', 'GET'
'x-jwt', '***'
'accept', 'application/json'
'connection', 'close'

[2021-02-09 14:23:14.222][24][debug][http] [source/common/http/filter_manager.cc:755] [C1876][S15748738241223205728] request end stream
[2021-02-09 14:23:14.222][24][debug][router] [source/common/router/router.cc:425] [C1876][S15748738241223205728] cluster 'some_cluster' match for URL '/...'
[2021-02-09 14:23:14.222][24][debug][router] [source/common/router/router.cc:582] [C1876][S15748738241223205728] router decoding headers:
':authority', '...'
':path', '/...'
':method', 'GET'
':scheme', 'http'
'x-jwt', '***'
'accept', 'application/json'
'x-forwarded-for', 'x.x.x.x'
'x-forwarded-proto', 'https'
'x-envoy-internal', 'true'
'x-request-id', 'f3859bd9-2f6b-4e97-af6a-1ead24aef8a7'
'x-envoy-expected-rq-timeout-ms', '303000'

[2021-02-09 14:23:14.222][24][debug][router] [source/common/router/upstream_request.cc:354] [C1876][S15748738241223205728] pool ready
[2021-02-09 14:23:14.223][24][debug][router] [source/common/router/router.cc:1026] [C1876][S15748738241223205728] upstream reset: reset reason: connection termination, transport failure reason:
[2021-02-09 14:23:14.223][24][debug][http] [source/common/http/filter_manager.cc:839] [C1876][S15748738241223205728] Sending local reply with details upstream_reset_before_response_started{connection termination}
[2021-02-09 14:23:14.223][24][debug][http] [source/common/http/conn_manager_impl.cc:1429] [C1876][S15748738241223205728] closing connection due to connection close header
[2021-02-09 14:23:14.223][24][debug][http] [source/common/http/conn_manager_impl.cc:1484] [C1876][S15748738241223205728] encoding headers via codec (end_stream=false):
':status', '503'
'content-length', '95'
'content-type', 'text/plain'
'date', 'Tue, 09 Feb 2021 14:23:13 GMT'
'server', 'envoy'
'connection', 'close'

[2021-02-09 14:23:14.223][24][debug][connection] [source/common/network/connection_impl.cc:132] [C1876] closing data_to_write=248 type=2
[2021-02-09 14:23:14.223][24][debug][connection] [source/common/network/connection_impl_base.cc:47] [C1876] setting delayed close timer with timeout 1000 ms
[2021-02-09 14:23:14.223][24][debug][connection] [source/common/network/connection_impl.cc:696] [C1876] write flush complete

aqua777 avatar Feb 09 '21 15:02 aqua777

So offhand this still looks like an upstream disconnect. Any chance you can capture a package trace to see if that's what is happening?

Are you using HTTP/1.1 by any chance? There's a known race where if upstream sends response1 and closes the connection without sending normal connection close headers, that Enovy will read the response and can reassign the connection to a new stream before picking up the tcp FIN, resulting in near immediate reset.

On Tue, Feb 9, 2021 at 10:50 AM aqua777 [email protected] wrote:

We've managed to capture one of the requests resulting in 503 response code, see the output below:

[2021-02-09 14:23:14.220][24][debug][conn_handler] [source/server/connection_handler_impl.cc:501] [C1876] new connection [2021-02-09 14:23:14.222][24][debug][http] [source/common/http/conn_manager_impl.cc:254] [C1876] new stream [2021-02-09 14:23:14.222][24][debug][http] [source/common/http/conn_manager_impl.cc:886] [C1876][S15748738241223205728] request headers complete (end_stream=true): ':authority', '...' ':path', '/...' ':method', 'GET' 'x-jwt', '***' 'accept', 'application/json' 'connection', 'close'

[2021-02-09 14:23:14.222][24][debug][http] [source/common/http/filter_manager.cc:755] [C1876][S15748738241223205728] request end stream [2021-02-09 14:23:14.222][24][debug][router] [source/common/router/router.cc:425] [C1876][S15748738241223205728] cluster 'some_cluster' match for URL '/...' [2021-02-09 14:23:14.222][24][debug][router] [source/common/router/router.cc:582] [C1876][S15748738241223205728] router decoding headers: ':authority', '...' ':path', '/...' ':method', 'GET' ':scheme', 'http' 'x-jwt', '***' 'accept', 'application/json' 'x-forwarded-for', '10.64.x.x' 'x-forwarded-proto', 'https' 'x-envoy-internal', 'true' 'x-request-id', 'f3859bd9-2f6b-4e97-af6a-1ead24aef8a7' 'x-envoy-expected-rq-timeout-ms', '303000'

[2021-02-09 14:23:14.222][24][debug][router] [source/common/router/upstream_request.cc:354] [C1876][S15748738241223205728] pool ready [2021-02-09 14:23:14.223][24][debug][router] [source/common/router/router.cc:1026] [C1876][S15748738241223205728] upstream reset: reset reason: connection termination, transport failure reason: [2021-02-09 14:23:14.223][24][debug][http] [source/common/http/filter_manager.cc:839] [C1876][S15748738241223205728] Sending local reply with details upstream_reset_before_response_started{connection termination} [2021-02-09 14:23:14.223][24][debug][http] [source/common/http/conn_manager_impl.cc:1429] [C1876][S15748738241223205728] closing connection due to connection close header [2021-02-09 14:23:14.223][24][debug][http] [source/common/http/conn_manager_impl.cc:1484] [C1876][S15748738241223205728] encoding headers via codec (end_stream=false): ':status', '503' 'content-length', '95' 'content-type', 'text/plain' 'date', 'Tue, 09 Feb 2021 14:23:13 GMT' 'server', 'envoy' 'connection', 'close'

[2021-02-09 14:23:14.223][24][debug][connection] [source/common/network/connection_impl.cc:132] [C1876] closing data_to_write=248 type=2 [2021-02-09 14:23:14.223][24][debug][connection] [source/common/network/connection_impl_base.cc:47] [C1876] setting delayed close timer with timeout 1000 ms [2021-02-09 14:23:14.223][24][debug][connection] [source/common/network/connection_impl.cc:696] [C1876] write flush complete

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/envoyproxy/envoy/issues/14981#issuecomment-776040664, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELALPKR3CDHEKREUCQBYM3S6FKVDANCNFSM4XJJRKNA .

alyssawilk avatar Feb 09 '21 16:02 alyssawilk

@alyssawilk AFAIK, these requests are using HTTP/1.1 indeed. By upstream disconnect do you mean that in your interpretation the connection is being reset by the upstream side?

What would you recommend to capture package trace? Something like tcpdump or do you have other tools in mind?

aqua777 avatar Feb 09 '21 17:02 aqua777

Yeah, so if I had to bet I'd guess your upstream is sending a response without a connection close header, then closing the connection. a TCP dump will tell you if this is indeed what's happening (if upstream is sending that TCP FIN), and confirm or deny you're hitting the race I mentioned. Unfortunately there's not a ton Envoy can do here today - generally we encourage folks to make sure if the upstream is closing HTTP/1.1 connections it use the connection: close header (which will cause Envoy to not reuse the connection, and avoid the race entirely).

On Tue, Feb 9, 2021 at 12:28 PM aqua777 [email protected] wrote:

@alyssawilk https://github.com/alyssawilk AFAIK, these requests are using HTTP/1.1 indeed. By upstream disconnect do you mean that in your interpretation the connection is being reset by the upstream side?

What would you recommend to capture package trace? Something like tcpdump or do you have other tools in mind?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/envoyproxy/envoy/issues/14981#issuecomment-776106438, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELALPNLD44Z47K4BAPV3RLS6FWDVANCNFSM4XJJRKNA .

alyssawilk avatar Feb 09 '21 17:02 alyssawilk

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.

github-actions[bot] avatar Mar 14 '21 20:03 github-actions[bot]

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.

github-actions[bot] avatar Mar 21 '21 20:03 github-actions[bot]

@aqua777 So did you finally manage to figure out the root cause ? I am getting quite similar issue today. It seems like @alyssawilk explained; but I don't know how to fix it. Any hint ? Thanks!

[2021-05-10 00:37:31.782][3549452][debug][router] [source/common/router/router.cc:425] [C0][S15323405275991739010] cluster '...' match for URL '...'
[2021-05-10 00:37:31.783][3549452][debug][router] [source/common/router/router.cc:582] [C0][S15323405275991739010] router decoding headers:
':authority', '...:8443'
':path', '...'
':method', 'GET'
':scheme', 'http'
'user-agent', 'curl/7.64.1'
'accept', '*/*'
'x-forwarded-proto', 'https'
'x-request-id', 'a0fbb5a1-6680-4274-a213-2fc3184a0c71'
'x-envoy-expected-rq-timeout-ms', '15000'

[2021-05-10 00:37:31.783][3549452][debug][pool] [source/common/http/conn_pool_base.cc:79] queueing stream due to no available connections
[2021-05-10 00:37:31.783][3549452][debug][pool] [source/common/conn_pool/conn_pool_base.cc:106] creating a new connection
[2021-05-10 00:37:31.783][3549452][debug][client] [source/common/http/codec_client.cc:41] [C1] connecting
[2021-05-10 00:37:31.783][3549452][debug][connection] [source/common/network/connection_impl.cc:860] [C1] connecting to 10.28.1.4:8443
[2021-05-10 00:37:31.783][3549452][debug][connection] [source/common/network/connection_impl.cc:876] [C1] connection in progress
[2021-05-10 00:37:31.784][3549452][trace][http] [source/common/http/filter_manager.cc:498] [C0][S15323405275991739010] decode headers called: filter=0xca6da00 status=1
[2021-05-10 00:37:31.784][3549452][trace][misc] [source/common/event/scaled_range_timer_manager_impl.cc:60] enableTimer called on 0xca6d980 for 300000ms, min is 300000ms
[2021-05-10 00:37:31.784][3549452][trace][http] [source/common/http/http1/codec_impl.cc:620] [C0] parsed 155 bytes
[2021-05-10 00:37:31.784][3549452][trace][connection] [source/common/network/connection_impl.cc:548] [C0] socket event: 2
[2021-05-10 00:37:31.784][3549452][trace][connection] [source/common/network/connection_impl.cc:657] [C0] write ready
[2021-05-10 00:37:32.062][3549452][trace][connection] [source/common/network/connection_impl.cc:548] [C1] socket event: 2
[2021-05-10 00:37:32.062][3549452][trace][connection] [source/common/network/connection_impl.cc:657] [C1] write ready
[2021-05-10 00:37:32.062][3549452][debug][connection] [source/common/network/connection_impl.cc:666] [C1] connected
[2021-05-10 00:37:32.062][3549452][trace][connection] [source/common/network/connection_impl.cc:407] [C1] raising connection event 2
[2021-05-10 00:37:32.062][3549452][debug][client] [source/common/http/codec_client.cc:80] [C1] connected
[2021-05-10 00:37:32.063][3549452][debug][pool] [source/common/conn_pool/conn_pool_base.cc:225] [C1] attaching to next stream
[2021-05-10 00:37:32.063][3549452][debug][pool] [source/common/conn_pool/conn_pool_base.cc:130] [C1] creating stream
[2021-05-10 00:37:32.063][3549452][debug][router] [source/common/router/upstream_request.cc:354] [C0][S15323405275991739010] pool ready
[2021-05-10 00:37:32.063][3549452][trace][connection] [source/common/network/connection_impl.cc:465] [C1] writing 291 bytes, end_stream false
[2021-05-10 00:37:32.063][3549452][trace][connection] [source/common/network/connection_impl.cc:657] [C1] write ready
[2021-05-10 00:37:32.063][3549452][trace][connection] [source/common/network/raw_buffer_socket.cc:68] [C1] write returns: 291
[2021-05-10 00:37:32.063][3549452][trace][connection] [source/common/network/connection_impl.cc:548] [C1] socket event: 2
[2021-05-10 00:37:32.063][3549452][trace][connection] [source/common/network/connection_impl.cc:657] [C1] write ready
[2021-05-10 00:37:32.472][3549452][trace][connection] [source/common/network/connection_impl.cc:548] [C1] socket event: 3
[2021-05-10 00:37:32.472][3549452][trace][connection] [source/common/network/connection_impl.cc:657] [C1] write ready
[2021-05-10 00:37:32.472][3549452][trace][connection] [source/common/network/connection_impl.cc:586] [C1] read ready. dispatch_buffered_data=false
[2021-05-10 00:37:32.472][3549452][trace][connection] [source/common/network/raw_buffer_socket.cc:25] [C1] read returns: 0
[2021-05-10 00:37:32.472][3549452][debug][connection] [source/common/network/connection_impl.cc:634] [C1] remote close
[2021-05-10 00:37:32.472][3549452][debug][connection] [source/common/network/connection_impl.cc:241] [C1] closing socket: 0
[2021-05-10 00:37:32.472][3549452][trace][connection] [source/common/network/connection_impl.cc:407] [C1] raising connection event 0
[2021-05-10 00:37:32.472][3549452][trace][http] [source/common/http/http1/codec_impl.cc:571] [C1] parsing 0 bytes
[2021-05-10 00:37:32.472][3549452][trace][http] [source/common/http/http1/codec_impl.cc:620] [C1] parsed 0 bytes
[2021-05-10 00:37:32.472][3549452][debug][client] [source/common/http/codec_client.cc:99] [C1] disconnect. resetting 1 pending requests
[2021-05-10 00:37:32.472][3549452][debug][client] [source/common/http/codec_client.cc:125] [C1] request reset
[2021-05-10 00:37:32.472][3549452][trace][main] [source/common/event/dispatcher_impl.cc:213] item added to deferred deletion list (size=1)
[2021-05-10 00:37:32.472][3549452][debug][router] [source/common/router/router.cc:1026] [C0][S15323405275991739010] upstream reset: reset reason: connection termination, transport failure reason:
[2021-05-10 00:37:32.476][3549452][debug][http] [source/common/http/filter_manager.cc:839] [C0][S15323405275991739010] Sending local reply with details upstream_reset_before_response_started{connection termination}
[2021-05-10 00:37:32.476][3549452][trace][misc] [source/common/event/scaled_range_timer_manager_impl.cc:60] enableTimer called on 0xca6d980 for 300000ms, min is 300000ms
[2021-05-10 00:37:32.476][3549452][debug][http] [source/common/http/conn_manager_impl.cc:1484] [C0][S15323405275991739010] encoding headers via codec (end_stream=false):
':status', '503'
'content-length', '95'
'content-type', 'text/plain'
'date', 'Sun, 09 May 2021 17:37:32 GMT'
'server', 'envoy'

ngtuna avatar May 09 '21 17:05 ngtuna

This line makes me very confused

[2021-05-10 00:37:32.476][3549452][debug][http] [source/common/http/filter_manager.cc:839] [C0][S15323405275991739010] Sending local reply with details upstream_reset_before_response_started{connection termination}

ngtuna avatar May 09 '21 19:05 ngtuna

from https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/response_code_details

The upstream connection was reset after a response was started. This may include further details about the cause of the disconnect.

So theoretically your upstream is closing the connection before it sends any part of the response.

If there's areas we can improve docs here to make it easier to understand, please let us know!

alyssawilk avatar May 10 '21 16:05 alyssawilk

I encounter this problem too! my upstream server is nginx,and the log of nginx that back to envoy is : "PRI * HTTP/2.0" 400 157 "-" "-" "-". That is so wired that envoy send a request to nginx base on http1.1, why nginx treat it as http2.0 or grpc request

elias4ty avatar Jan 13 '22 08:01 elias4ty

@aqua777 Were you able to identify the problem? We are facing a similar issue in our production @alyssawilk Is configuring envoy to retry on reset right way to workaround the issue?

ivpr avatar Apr 24 '22 13:04 ivpr

@ivpr we are getting similar error after updating envoy to 1.17 - in our case , it is for every request. Did configuring retry on reset helped?

rajetta avatar May 05 '22 03:05 rajetta

We are receiving this as well, 3 requests out of 24,000+ had a 503 UC error, not sure why. Pods are all healthy, have been up for days, resources all low....anyone figure this out?

jbilliau-rcd avatar Jun 13 '22 19:06 jbilliau-rcd

We are also facing this issue and have no idea why. All pods are up and worked fine in the past. After Envoy integration, this changed and we now see above errors.

benedikt-roth avatar Jul 11 '22 13:07 benedikt-roth

We ended up implementing Envoy configuration to retry the requests once when connection to backend servers is reset. This eliminated the majority of errors although we still get some.

aqua777 avatar Jul 11 '22 13:07 aqua777