Skip to content

RST_STREAM sent to downstream client instead of remaining DATA, HEADERS on end stream #30149

Closed

Description

@niloc132

Title: RST_STREAM sent to downstream client instead of remaining DATA, HEADERS on end stream

Description:
In some circumstances, it is possible for envoy to skip sending remaining DATA, HEADERS frames and instead send RST_STREAM, resulting in errors in the downstream client. In this case, we have a gRPC service returning data to a client, and some client implementations get an error instead of seeing the expected grpc-status: 0 trailers. The stream needs to be bidirectional, with the client having not half-closed from its side yet (which in some cases offers a potential workaround).

Downstream error reported by netty-grpc:

io.grpc.StatusRuntimeException: UNAVAILABLE: RST_STREAM closed stream. HTTP/2 error code: NO_ERROR
	at io.grpc.Status.asRuntimeException(Status.java:539)
	at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:487)
	at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
	at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
	at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)

Downstream error reported by okhttp-grpc:

io.grpc.StatusRuntimeException: INTERNAL: No error: A GRPC status of OK should have been sent
Rst Stream
	at io.grpc.Status.asRuntimeException(Status.java:537)
	at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:481)
	at io.grpc.internal.DelayedClientCall$DelayedListener$3.run(DelayedClientCall.java:489)
	at io.grpc.internal.DelayedClientCall$DelayedListener.delayOrExecute(DelayedClientCall.java:453)
	at io.grpc.internal.DelayedClientCall$DelayedListener.onClose(DelayedClientCall.java:486)
	at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:567)

No error is reported when using the Python gRPC client (which we understand to be a cython wrapper around the C++ client). We speculate that the C++ client might be handling data faster than the Java clients, and that the bug might be rooted in Envoy not being prepared to forward all remaining data for some reason.

Note that I have not validated this issue in non-gRPC contexts, but there is nothing specific about the envoy.yaml to gRPC, so it seems likely that this impacts other h2 upstream+downstream bidirectional streaming use cases as well.

Repro steps:

  • Create a simple gRPC server with a bidirectional service. Implement the server so that it sends around 4MB to the client when connected, the immediately half-closes its side of the stream. The example project below demonstrates the issue with both a grpc-java and python server implementation. Note that the error can still happen with smaller payloads, but it seems less likely.
  • A client in turn should be implemented that connects and waits for output, without half-closing, logging the bytes it receives and the eventual success/failure status. Confirm that directly connecting to the server behaves as expecting, showing all data and status received successfully.
  • A simple Envoy instance should be placed between the client and server, offering h2 to downstream users, and only connecting using h2 to upstream clusters. It may be possible to simplify further, the included example is intended to also disable a variety of timeouts.
  • Connect the client to the server through envoy. Expected behavior is that results are the same without envoy, actual observed behavior is that the client usually sees an error, despite envoy access logs seeming to show success.

To try this out, we've built a sample git repository to demonstrate the issue at https://github.com/niloc132/envoy-rst-stream. Instructions are there to run the (default) Java server and Java client, but either can be replaced with a Python implementation.

Admin and Stats Output:

Include the admin output for the following endpoints: /stats,
/clusters, /routes, /server_info. For more information, refer to the
admin endpoint documentation.
http://localhost:9090/stats https://gist.github.com/niloc132/d6b5c778ab2b79b8a8c4781dc80ac40b

http://localhost:9090/clusters

server::observability_name::server
server::default_priority::max_connections::1024
server::default_priority::max_pending_requests::1024
server::default_priority::max_requests::1024
server::default_priority::max_retries::3
server::high_priority::max_connections::1024
server::high_priority::max_pending_requests::1024
server::high_priority::max_requests::1024
server::high_priority::max_retries::3
server::added_via_api::false
server::192.168.48.2:8080::cx_active::1
server::192.168.48.2:8080::cx_connect_fail::0
server::192.168.48.2:8080::cx_total::1
server::192.168.48.2:8080::rq_active::0
server::192.168.48.2:8080::rq_error::0
server::192.168.48.2:8080::rq_success::1
server::192.168.48.2:8080::rq_timeout::0
server::192.168.48.2:8080::rq_total::1
server::192.168.48.2:8080::hostname::java-server
server::192.168.48.2:8080::health_flags::healthy
server::192.168.48.2:8080::weight::1
server::192.168.48.2:8080::region::
server::192.168.48.2:8080::zone::
server::192.168.48.2:8080::sub_zone::
server::192.168.48.2:8080::canary::false
server::192.168.48.2:8080::priority::0
server::192.168.48.2:8080::success_rate::-1
server::192.168.48.2:8080::local_origin_success_rate::-1

http://localhost:9090/routes - This doesn't appear to be a valid admin URL.

http://localhost:9090/server_info - https://gist.github.com/niloc132/6516b8fcae91a7f2c4ae23024aeb5b2c

Config:
See https://github.com/niloc132/envoy-rst-stream/blob/main/envoy.yaml along with the rest of the repo to reproduce this issue

Logs:
Access log entry for the request, showing 4mb of pb payload sent "successfully", despite client showing error:

envoy-rst-stream-envoy-1        | [2023-10-12T16:17:40.943Z] "POST /org.example.TestService/Hello HTTP/2" 200 - 0 4000010 190 - "-" "grpc-java-netty/1.58.0" "d02b9201-cb74-4cc6-8b80-012146aafe04" "localhost:8000" "192.168.48.2:8080"

This log has level=trace, uptsream=off, dns=off, config=off (and includes the access logs with the above line:
https://gist.github.com/niloc132/521a45c0eb38c7733593c56e8c06fc02
Excerpt which appears to show that envoy says it received the trailers from upstream and sent to client:

envoy-rst-stream-envoy-1        | [2023-10-12 16:17:41.133][45][trace][router] [source/common/router/upstream_request.cc:315] [Tags: "ConnectionId":"4","StreamId":"9345982487776441659"] upstream response trailers:
envoy-rst-stream-envoy-1        | 'grpc-status', '0'
envoy-rst-stream-envoy-1        | 
envoy-rst-stream-envoy-1        | [2023-10-12 16:17:41.133][45][debug][router] [source/common/router/upstream_request.cc:469] [Tags: "ConnectionId":"4","StreamId":"9345982487776441659"] resetting pool request
envoy-rst-stream-envoy-1        | [2023-10-12 16:17:41.133][45][debug][client] [source/common/http/codec_client.cc:158] [Tags: "ConnectionId":"5"] request reset
envoy-rst-stream-envoy-1        | [2023-10-12 16:17:41.133][45][trace][main] [source/common/event/dispatcher_impl.cc:251] item added to deferred deletion list (size=1)
envoy-rst-stream-envoy-1        | [2023-10-12 16:17:41.133][45][debug][pool] [source/common/conn_pool/conn_pool_base.cc:215] [Tags: "ConnectionId":"5"] destroying stream: 0 remaining
envoy-rst-stream-envoy-1        | [2023-10-12 16:17:41.133][45][trace][main] [source/common/event/dispatcher_impl.cc:251] item added to deferred deletion list (size=2)
envoy-rst-stream-envoy-1        | [2023-10-12 16:17:41.133][45][trace][main] [source/common/event/dispatcher_impl.cc:251] item added to deferred deletion list (size=3)
envoy-rst-stream-envoy-1        | [2023-10-12 16:17:41.133][45][debug][http] [source/common/http/conn_manager_impl.cc:1759] [Tags: "ConnectionId":"4","StreamId":"9345982487776441659"] encoding trailers via codec:
envoy-rst-stream-envoy-1        | 'grpc-status', '0'
envoy-rst-stream-envoy-1        | 
envoy-rst-stream-envoy-1        | [2023-10-12 16:17:41.133][45][debug][http] [source/common/http/conn_manager_impl.cc:221] [Tags: "ConnectionId":"4","StreamId":"9345982487776441659"] doEndStream() resetting stream
envoy-rst-stream-envoy-1        | [2023-10-12 16:17:41.133][45][debug][http] [source/common/http/conn_manager_impl.cc:1798] [Tags: "ConnectionId":"4","StreamId":"9345982487776441659"] stream reset: reset reason: local reset, response details: -

Wireshark screencap showing upstream (192.168.48.2:8080) sending envoy (192.168.48.3) HEADERS with end of stream set to true, then envoy sending RST_STREAM to both downstream client (192.168.48.1) and upstream. These messages are highlighted - other DATA messages from upstream->envoy and envoy->client can also be seen.

screenshot857

Conversely, here's a successful Python client (irritatingly both streams had id 1, so be sure to check source/destination IP)
screenshot858

And here's a Java client also succeeding through envoy
screenshot859

I can provide the pcapng file for any of these if desired, but the example project should easily reproduce this as well.

Call Stack:
N/A

Other notes:
Through wireshark and through setting additional custom trailers on server responses, we've ruled out the python client getting the RST_STREAM as well but incorrectly reporting success. We also tested with both the Netty and OkHttp clients and both exhibit the error, giving a degree of confidence that this is an envoy issue rather than both implementations having the same bug.

Activity

  1. added
    triage
    on Oct 12, 2023
  2. niloc132 commented on Oct 12, 2023

    @niloc132
    Author

    The 1.27.1 release with a fix for resetting streams was just brought to my attention - I tweaked the linked project to use the v1.27.1 envoy image, and can confirm that this did not fix the issue.

  3. kyessenov commented on Oct 17, 2023

    @kyessenov
    Contributor
  4. added and removed
    triage
    on Oct 17, 2023
  5. github-actions commented on Nov 16, 2023

    @github-actions

    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.

  6. added
    stale
    on Nov 16, 2023
  7. devinrsmith commented on Nov 16, 2023

    @devinrsmith

    Adding comment to trigger activity. Hoping project member can take a look. Thanks!

  8. removed
    stale
    on Nov 17, 2023
  9. alyssawilk commented on Nov 29, 2023

    @alyssawilk
    Contributor

    Sorry we haven't been able to get to this yet. It could be a codec issue or an Envoy issue and we're just now changing the underlying codec in #31086. Can you see if that addresses the problem and if not I'll try to take a look?

  10. devinrsmith commented on Nov 29, 2023

    @devinrsmith

    Is there an easy way to get a docker image for an outstanding PR? I see https://github.com/envoyproxy/envoy/tree/main/ci#ubuntu-envoy-image, but it looks like envoyproxy/envoy-build-ubuntu hasn't been updated recently.

  11. 30 remaining items

  12. DerekTBrown commented on Sep 11, 2024

    @DerekTBrown

    I believe I am still observing this issue with the patched version (but would appreciate if someone could validate my method):

    • I launched an instance of istio-testing/proxyv2:1.24-alpha.ceeeab0e900812087dae52d851584a73d5939290-distroless (a version of the Istio proxy containing the patched version of Envoy).
    • I added a static_layer with "envoy.reloadable_features.allow_multiplexed_upstream_half_close": true
    • I am still observing (13 INTERNAL: Received RST_STREAM with code 0 (Call ended without gRPC status))
  13. alyssawilk commented on Sep 11, 2024

    @alyssawilk
    Contributor

    Any chance you could provide a repro case and/or logs? There are definitely many reasons things can go south and while I'm unsure if there are other failure modes which would cause this particular error, it'd definitely be helpful to have the additional data to better assess.

  14. justinfx commented on Sep 11, 2024

    @justinfx

    I too would love to see a repro. We still don't know how Envoy manages to get into this state in production. But so far we have been running ok since Sunday with a combination of:

    • dev envoy with this runtime feature fix enabled
    • remove overrides for http2_protocol_options settings
    • using a max_connection_duration of 300s for upstream cluster

    A repro would be cool since we don't know if we have fixed it or are just lucky so far.

    It does sound similar to envoy issue #8114

  15. DerekTBrown commented on Sep 11, 2024

    @DerekTBrown

    @justinfx @alyssawilk I spent some time digging into this. It looks like there were >1 reasons why we were seeing missing HEADERS in our environment. The runtime feature fix enabled seems to have reduced the error rate, but I am seeing grpc-go send STREAM_RST without trailers as well:

    grpc/grpc-go#7623

  16. alyssawilk commented on Sep 16, 2024

    @alyssawilk
    Contributor

    Glad this has reduced your error rate. I don't think the information in the attached issue is enough for us to repro. Any chance again we could get more detailed info and/or logs? I'm happy to supply you with email addresses if there's info you can share but don't want posted on the public internet

  17. yanavlasov commented on Sep 17, 2024

    @yanavlasov
    Contributor

    I'm unable to recreate this problem using the repro case from @niloc132

    @DerekTBrown from your last comment it is unclear to me if the problem is related to Envoy or not. If you think this is Envoy related, please provide a repro case, preferably without Istio involved. I think opening a new Issue would be best.

  18. justinfx commented on Sep 18, 2024

    @justinfx

    In my case we were never able to actually isolate a repro. It would occur at random. But at this point we have been running a combination of this new fix feature via the envoy dev container image, and also a few configuration tweaks, and it has been running solid for 1.5 weeks. I do not know if it was the fix in this issue, or the tweaks we made to the config, but if it is no longer happening, I am not inclined to investigate any further

  19. DerekTBrown commented on Sep 23, 2024

    @DerekTBrown

    @DerekTBrown from your last comment it is unclear to me if the problem is related to Envoy or not. If you think this is Envoy related, please provide a repro case, preferably without Istio involved. I think opening a new Issue would be best.

    I believe this issue has been resolved on the Envoy side. I was observing both this issue, and a separate issue with the same symptoms (i.e. no trailers), but coming directly from the application itself
    (grpc/grpc-go#7623). Sorry for the false alarm.

  20. justinfx commented on Oct 30, 2024

    @justinfx

    Is this part of a recent tagged release? I didnt see it.

  21. alyssawilk commented on Oct 30, 2024

    @alyssawilk
    Contributor

    Yes, but AFIK still off by default as the change was high risk and internal testing is not complete.

  22. justinfx commented on Oct 30, 2024

    @justinfx

    I see. FWIW we have been running the first dev container that contained the commit, since it was pushed, and have not experienced the issue since.

  23. jacobmikesell commented on Nov 15, 2024

    @jacobmikesell

    We've still been encountering this on a streaming RPC after updating to enable this change

  24. alyssawilk commented on Nov 18, 2024

    @alyssawilk
    Contributor

    To confirm did you both update Envoy and enable the feature? It's still off by default in the latest release.

  25. SvenGasterstaedt commented on Jun 24, 2025

    @SvenGasterstaedt

    @alyssawilk i was wondering if the internal testing has completed successfully.

    We are encountering the mentioned issue on a managed instance of istio/enovy via aks. Therefore it is not possible for us to set feature flags and are depend on a release containing this (breaking) changes.

    Do you have an update on the current state and when it will be in a stable release?

    Thank you in advance

  26. frbvianna commented on Jul 22, 2025

    @frbvianna

    @alyssawilk is this a valid way of setting the feature flag?

    layered_runtime:
      layers:
      - name: static-layer
        static_layer:
          envoy.reloadable_features.allow_multiplexed_upstream_half_close: true

    I've added the above to the envoy config YAML, but still see the issue happening very frequently for my bidi stream RPC using a gRPC-Go client. I'm using Envoy v1.34 distroless image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/httpbugno stalebot

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions