Skip to content

HTTP/2 RST_STREAM(NO_ERROR) after a complete gRPC response drops pending downstream encode #48192

Not planned

Description

@shk3

Description:
The bug is a client-stream or bidi RPC whose request half stays open. The grpc-go server sends ~100KiB, then trailers (grpc-status: 0), then RST_STREAM(NO_ERROR). That sequence is legal (RFC 9113 §8.1, grpc-go#834). The RFC says the client must not discard the response.

Through Envoy (HTTP/2 both sides, 32KiB buffers, 64KiB stream window) Recv often fails:

rpc error: code = Internal desc = stream terminated by RST_STREAM with error code: INTERNAL_ERROR

Envoy still counts the RPC as HTTP 200. The failure is racy. Small bodies often succeed. Bodies larger than the stream window often fail.

This is not unary. Unary Invoke sets request END_STREAM. grpc-go then does not send RST_STREAM. Envoy delivers the body.

Expected: Envoy delivers the body and trailers it already decoded. After the encoder drains, Envoy may send RST_STREAM(NO_ERROR) if the request half is still open.

Results (~100KiB, request half open, five fresh connections):

Envoy flags Recv
distroless-v1.37.2 none 3/5 OK
distroless-v1.39.3 http_preserve_rst_no_error: true 2/5 OK

Direct to the server, no Envoy: Recv OK with the request half still open. Unary Invoke through 1.37.2: OK.

1.39.3: 6eb0d2d97489ec1b4e1584a004f5de443d97a41b/1.39.3/Clean/RELEASE/BoringSSL. /runtime envoy.reloadable_features.http_preserve_rst_no_error final_value: true.

Why #44749 is not enough: The flag only special-cases an inbound upstream RST_STREAM(NO_ERROR) after END_STREAM, and only if the inbound codec still has body or trailers. It does not stop HCM doEndStream() from sending a local downstream RST_STREAM(NO_ERROR) when the response is complete and the request half is still open. It also does not see bytes already in pending_send_data_. The 1.39.3 run matches that.

Fix: If upstream response END_STREAM is already decoded, do not reset downstream until encode drains. Then send RST_STREAM(NO_ERROR). nginx already ignores this RST after a complete response (ticket #1792). Same class of bug: #38206, #30149.

Repro steps:
Same shape as https://github.com/niloc132/envoy-rst-stream.

  1. grpc-go server: client-stream or bidi. Recv once. Send ~100KiB. Return. Do not wait for request END_STREAM.
  2. Envoy: HTTP/2 downstream and upstream. Router only. per_connection_buffer_limit_bytes: 32768. initial_stream_window_size: 65536. See Config. These match Envoy edge-proxy buffer guidance.
  3. grpc-go client: NewStream with ClientStreams: true and ServerStreams: true. SendMsg. Do not send request END_STREAM. RecvMsg. New connection each try. Five tries.

Images: envoyproxy/envoy:distroless-v1.37.2 with no extra flags. envoyproxy/envoy:distroless-v1.39.3 with:

layered_runtime:
  layers:
  - name: static_layer
    static_layer:
      envoy.reloadable_features.http_preserve_rst_no_error: true

Admin and Stats Output:
distroless-v1.37.2 (5afe27fb…/1.37.2). Request half open. Client 3/5 OK (~102422 bytes). /clusters: rq_success::3 rq_error::2 rq_total::5. Envoy records all five as HTTP 200.

cluster.backend.upstream_rq_200: 5
cluster.backend.upstream_rq_rx_reset: 2
cluster.backend.upstream_rq_tx_reset: 3
cluster.backend.http2.rx_reset: 5
cluster.backend.http2.tx_reset: 3
http2.tx_reset: 5
http.ingress.downstream_rq_2xx: 5
http.ingress.downstream_rq_response_before_rq_complete: 5
http.ingress.downstream_rq_rx_reset: 5
http.ingress.downstream_rq_tx_reset: 2
http.ingress.downstream_cx_protocol_error: 4
cluster.backend.upstream_cx_rx_bytes_total: 512911
cluster.backend.upstream_cx_tx_bytes_total: 1201
http.ingress.downstream_cx_tx_bytes_total: 505170

distroless-v1.39.3 /runtime:

"envoy.reloadable_features.http_preserve_rst_no_error": {
  "layer_values": ["true"],
  "final_value": "true"
}

Request half open: 2/5 OK. Last error: RST_STREAM INTERNAL_ERROR.

Config:

admin:
  address:
    socket_address: { address: 0.0.0.0, port_value: 9901 }
static_resources:
  listeners:
  - name: ingress
    address:
      socket_address: { address: 0.0.0.0, port_value: 10000 }
    per_connection_buffer_limit_bytes: 32768
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          stat_prefix: ingress
          codec_type: HTTP2
          http2_protocol_options:
            initial_stream_window_size: 65536
            initial_connection_window_size: 1048576
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
          route_config:
            virtual_hosts:
            - name: grpc
              domains: ["*"]
              routes:
              - match: { prefix: "/" }
                route:
                  cluster: backend
                  timeout: 15s
  clusters:
  - name: backend
    type: STRICT_DNS
    connect_timeout: 2s
    per_connection_buffer_limit_bytes: 32768
    typed_extension_protocol_options:
      envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
        "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
        explicit_http_config:
          http2_protocol_options:
            initial_stream_window_size: 65536
            initial_connection_window_size: 1048576
    load_assignment:
      cluster_name: backend
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: 127.0.0.1
                port_value: 50051

Logs:
Upstream grpc-go (GODEBUG=http2debug=2) on a fail, from #38206:

wrote HEADERS flags=END_HEADERS
wrote DATA
wrote HEADERS flags=END_STREAM|END_HEADERS
wrote RST_STREAM ErrCode=NO_ERROR

Local Envoy --log-level debug on distroless-v1.37.2. Two outcomes. Both keep the request half open.

After trailers are encoded: doEndStream() sends a local downstream RST_STREAM(NO_ERROR). The preserve flag does not cover this.

waiting for encode to complete
response complete
encoding trailers via codec:
'grpc-status', '0'
Codec completed encoding stream.
doEndStream() resetting stream
stream reset: reset reason: local reset, response details: -
sent reset code=0
sent reset code=2

While body is still inbound: Envoy treats the upstream RST as remote reset and sends INTERNAL_ERROR downstream. Unread bytes are recouped. They are already in pending_send_data_. The preserve flag does not see them.

Http2Visitor: remaining data payload: 16384, end_stream: false
remaining data payload: 4127, end_stream: false
upstream reset: reset reason: remote reset
Resetting stream due to upstream_reset_after_response_started{remote_reset}. Prior headers have already been sent
doEndStream() resetting stream
sent reset code=2
Recouping 4127 bytes of flow control window

Call Stack:
N/A. Envoy does not crash.

Activity

  1. added
    triage
    on Oct 10, 2026
  2. akasakariko commented on Oct 12, 2026

    @akasakariko

    I'd like to work on this

  3. akasakariko commented on Oct 13, 2026

    @akasakariko

    Stepping back from this one.

  4. bingqifan commented on Oct 21, 2026

    @bingqifan
    Contributor

    I’ve reproduced this. I’ll work on the fix.

  5. added and removed
    triage
    on Oct 23, 2026
  6. yanavlasov commented on Oct 23, 2026

    @yanavlasov
    Contributor

    Thanks. I suspect Envoy resets the stream if it received RTS_STREAM and it did not yet send END_STREAM due to full buffers.

  7. bingqifan commented on Oct 23, 2026

    @bingqifan
    Contributor

    Thanks! I’ve reproduced this scenario and added regression coverage with downstream output blocked by flow control. In my captured failure, HCM initiated the local downstream reset before Envoy processed the upstream RST_STREAM(NO_ERROR), while the downstream response END_STREAM was still pending.

  8. github-actions commented on Nov 22, 2026

    @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.

  9. added
    stale
    on Nov 22, 2026
  10. github-actions commented on Nov 29, 2026

    @github-actions

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/grpcarea/httpbugstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions