Skip to content

redis: test dropping an upstream reply with no pending request - #48205

Merged
botengyao merged 1 commit into
envoyproxy:mainfrom
wdauchy:wdauchy/redis-drop-reply-no-pending-request
Oct 12, 2026
Merged

botengyao merged 1 commit into
envoyproxy:mainfrom
wdauchy:wdauchy/redis-drop-reply-no-pending-request

Conversation

@wdauchy

@wdauchy wdauchy commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Commit Message: redis: test dropping an upstream reply with no pending request

ClientImpl::onRespValue() used to only ASSERT that a request was outstanding and then call pending_requests_.front(). When an upstream sent a reply while the pending request list was empty (a surplus or unsolicited reply), a release build read the std::list sentinel as a PendingRequest and crashed. The RESP3 change (#44936) added a guard that drops such a frame, but its comment and its only test cover a HELLO 3 init callback that closes the connection. This adds tests for a surplus or unsolicited reply on an established connection, broadens the comment, and adds a bug fix release note.

Additional Description:
We hit this in production on v1.39.x: an upstream Redis sent a reply while Envoy had no request pending on that connection, and the proxy crashed (fault address 0x3ff, stack DecoderImpl::parseSlice <- ClientImpl::onData). Stock envoyproxy/envoy:v1.39.3 reproduces it with a fake upstream that answers one command with two replies, or sends one unsolicited reply later.

On main, the guard added by #44936 already drops the frame and keeps the connection open, which is the behavior these tests pin. The new tests:

  • RedisClientImplTest.UnsolicitedReplyIsDropped, SurplusReplyInSameBufferIsDropped and ReplyAfterCloseInSameBufferIsDropped: the reply is dropped, the connection stays open without upstream_cx_protocol_error, and the next request gets its own reply. The last one covers a user callback that closes the client while the decoder still holds a later reply from the same buffer.
  • RedisProxyIntegrationTest.SurplusUpstreamReplyIsDropped and UnsolicitedUpstreamReplyIsDropped: through the real decoder, the client gets only the first reply, and the next command goes over the same upstream connection (upstream_cx_total = 1, upstream_cx_protocol_error = 0). They wait for the drop log line before sending the next command, so the surplus reply cannot be paired with it on a loaded machine.

A surplus reply that arrives while another request is pending is still paired with that request; RESP gives no way to detect it.

release/v1.36 to release/v1.39 are still affected. #44936 is not a candidate for backport, so the fix there would be the guard alone plus these tests. We carry exactly that on v1.39.3. Happy to open the backport PRs if maintainers agree.

Risk Level: Low (tests, a comment and a release note; no behavior change on main)
Testing: The five new tests abort on the !pending_requests_.empty() ASSERT without the guard (checked on v1.39.3), and pass on main.
Docs Changes: N/A
Release Notes: Added a bug fix note for the crash.

AI assistance: the investigation, the tests and this change were prepared with AI assistance (Claude Code and Cursor agent). We reviewed and understand all of it.

ClientImpl::onRespValue() used to only ASSERT that a request was
outstanding and then call pending_requests_.front(). When an upstream
sent a reply while the pending request list was empty, a surplus or
unsolicited reply, a release build read the std::list sentinel as a
PendingRequest and crashed (fault address 0x3ff in our case). Stock
v1.39.3 reproduces it with an upstream that answers one command with two
replies.

The RESP3 change (envoyproxy#44936) added a guard that drops such a frame, but its
comment and its only test cover a HELLO 3 init callback that closes the
connection. Nothing tests the surplus or unsolicited reply on an
established connection, and the crash fix has no release note.

Broaden the comment, add a bug fix release note, and add three
RedisClientImplTest cases (unsolicited reply, surplus reply in the same
buffer, reply after a user callback closed the client) and two
RedisProxyIntegrationTest cases that send a surplus reply in the same
write and an unsolicited reply through the real decoder. They check that
the reply is dropped, that the upstream connection stays open without a
protocol error, and that the next command on it gets its own reply.

Signed-off-by: William Dauchy <[email protected]>
Signed-off-by: Henry Wang <[email protected]>
@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #48205 was opened by wdauchy.

see: more, trace.

@wdauchy

wdauchy commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@wdauchy
wdauchy marked this pull request as ready for review October 11, 2026 13:54
@wdauchy
wdauchy requested a review from mattklein123 as a code owner October 11, 2026 13:54

@botengyao botengyao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the test improvement!

@botengyao
botengyao merged commit ca94a2e into envoyproxy:main Oct 12, 2026
27 checks passed
gavin-jeong added a commit to sendbird/envoy that referenced this pull request Oct 15, 2026
Upstream already fixed this. The guard landed on main in envoyproxy#44936
and envoyproxy#48205 added tests for it three days ago; that PR reproduces
the crash exactly as we did, with "a fake upstream that answers one command with
two replies". So this is a backport, not an original fix, and it should look
like the thing it is backporting.

Three changes from the first version:

  - The comment no longer claims upstream cannot reach this path. That was
    wrong, and measurably so: stock istio/proxyv2:1.31.1, with no Sendbird
    patches and no pub/sub, restarted twice in four rounds against a
    double-replying server while the patched build stayed at zero. The claim
    came from checking only one way in (subscribe is absent from upstream's
    command lists) and concluding there were none.

  - No stat is incremented. Upstream only logs. A counter here would be a
    permanent fork delta on a hunk that should dissolve the next time envoy
    moves -- which is the entire reason to match the text.

  - The tests are upstream's UnsolicitedReplyIsDropped, which asserts more than
    mine did: the connection stays Open, no protocol error is counted, and a
    subsequent request still completes, so a dropped frame cannot have shifted
    pending_requests_. The command-stats variant stays because this pin takes a
    different path there (command_ is a non-owning StatName that aborts in
    SymbolTable::fromSymbol once popped), and disabling command stats was
    measured not to be a workaround.

Upstream also drops RESP3 Push frames ahead of this check. That cannot be
ported: this pin's RespType has no Push member.

release/v1.36 through release/v1.39 are still affected upstream and no backport
PR is open yet. ae1505b (v1.39.2-dev) is in that range.
gavin-jeong added a commit to sendbird/envoy that referenced this pull request Oct 15, 2026
Upstream already fixed this. The guard landed on main in envoyproxy#44936
and envoyproxy#48205 added tests for it three days ago; that PR reproduces
the crash exactly as we did, with "a fake upstream that answers one command with
two replies". So this is a backport, not an original fix, and it should look
like the thing it is backporting.

Three changes from the first version:

  - The comment no longer claims upstream cannot reach this path. That was
    wrong, and measurably so: stock istio/proxyv2:1.31.1, with no Sendbird
    patches and no pub/sub, restarted twice in four rounds against a
    double-replying server while the patched build stayed at zero. The claim
    came from checking only one way in (subscribe is absent from upstream's
    command lists) and concluding there were none.

  - No stat is incremented. Upstream only logs. A counter here would be a
    permanent fork delta on a hunk that should dissolve the next time envoy
    moves -- which is the entire reason to match the text.

  - The tests are upstream's UnsolicitedReplyIsDropped, which asserts more than
    mine did: the connection stays Open, no protocol error is counted, and a
    subsequent request still completes, so a dropped frame cannot have shifted
    pending_requests_. The command-stats variant stays because this pin takes a
    different path there (command_ is a non-owning StatName that aborts in
    SymbolTable::fromSymbol once popped), and disabling command stats was
    measured not to be a workaround.

Upstream also drops RESP3 Push frames ahead of this check. That cannot be
ported: this pin's RespType has no Push member.

release/v1.36 through release/v1.39 are still affected upstream and no backport
PR is open yet. ae1505b (v1.39.2-dev) is in that range.
gavin-jeong added a commit to sendbird/envoy that referenced this pull request Oct 15, 2026
Upstream already fixed this. The guard landed on main in envoyproxy#44936
and envoyproxy#48205 added tests for it three days ago; that PR reproduces
the crash exactly as we did, with "a fake upstream that answers one command with
two replies". So this is a backport, not an original fix, and it should look
like the thing it is backporting.

Three changes from the first version:

  - The comment no longer claims upstream cannot reach this path. That was
    wrong, and measurably so: stock istio/proxyv2:1.31.1, with no Sendbird
    patches and no pub/sub, restarted twice in four rounds against a
    double-replying server while the patched build stayed at zero. The claim
    came from checking only one way in (subscribe is absent from upstream's
    command lists) and concluding there were none.

  - No stat is incremented. Upstream only logs. A counter here would be a
    permanent fork delta on a hunk that should dissolve the next time envoy
    moves -- which is the entire reason to match the text.

  - The tests are upstream's UnsolicitedReplyIsDropped, which asserts more than
    mine did: the connection stays Open, no protocol error is counted, and a
    subsequent request still completes, so a dropped frame cannot have shifted
    pending_requests_. The command-stats variant stays because this pin takes a
    different path there (command_ is a non-owning StatName that aborts in
    SymbolTable::fromSymbol once popped), and disabling command stats was
    measured not to be a workaround.

Upstream also drops RESP3 Push frames ahead of this check. That cannot be
ported: this pin's RespType has no Push member.

release/v1.36 through release/v1.39 are still affected upstream and no backport
PR is open yet. ae1505b (v1.39.2-dev) is in that range.
gavin-jeong pushed a commit to sendbird/envoy that referenced this pull request Nov 25, 2026
… the pending request

ClientImpl pairs each upstream reply with the oldest pending request. RESP
has no request id, so one lost or surplus reply shifts every later reply
onto the wrong request, and the op timeout never fires while replies keep
arriving. Upstream documents this limit in envoyproxy#48205.

Record the RESP2 reply type that each fixed-type command always gets
(EXISTS integer, GET bulk string or null, HGETALL array, ...). When a
non-error reply has another type, treat it like a decoder protocol error:
count upstream_cx_protocol_error and rq_error, report an outlier failure
and close the connection, which fails every pending request. Transaction
clients are not checked because the server answers +QUEUED inside MULTI.

JIRA: https://sendbird.atlassian.net/browse/CPLAT-13577
(cherry picked from commit 98c39cf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants