Skip to content

[CPLAT-12791] redis: do not crash on an upstream frame with no pending request - #28

Merged
gavin-jeong merged 3 commits into
release/v1.39.2-sendbird-customfrom
CPLAT-12791-redis-push-message-crash
Oct 15, 2026
Merged

gavin-jeong merged 3 commits into
release/v1.39.2-sendbird-customfrom
CPLAT-12791-redis-push-message-crash

Conversation

@gavin-jeong

Copy link
Copy Markdown

JIRA: https://sendbird.atlassian.net/browse/CPLAT-12791

ClientImpl::onRespValue assumed every frame from upstream answers a request we sent, and read pending_requests_.front() to find it. Pub/sub breaks that: once a connection is subscribed, the server pushes messages that answer nothing, so the queue can be empty.

Reading front() on an empty std::list is undefined, and in release builds it crashes several different ways depending on what is touched first. All of them are this one missing check.

Measured, not inferred

Three proxies in one pod on a dev arm64 node, against the same healthy 3-master redis cluster (cluster_state:ok, 16384 slots), differing only in image and config. Reproduced with three commands: subscribe on one connection, publish on another, wait.

proxy config result
v1.30.2-sendbird-custom-v0.0.2 (production today) enable_command_stats: true exit 133, assert failure: search != decode_map_.end()
v1.31.1-sendbird-custom-v0.0.1 enable_command_stats: true exit 137, OOMKilled
v1.31.1-sendbird-custom-v0.0.1 enable_command_stats: false exit 135, Bus error

Two things follow. It is not a regression from the 1.39.2 port — the branch in production fails identically. And disabling command stats is not a workaround, which is why both paths have a test here.

PendingRequest::command_ is a non-owning Stats::StatName, so with command stats on it reaches a freed symbol and RELEASE_ASSERT in SymbolTable::fromSymbol aborts; with them off the timer and callback references fault instead.

Why the fix belongs in this fork

Upstream envoy cannot reach this path: its supported-command lists contain no subscribe, so the splitter rejects the command before a subscription can exist. simpleCommands has it 0 times upstream and 1 time here, added by our own a298a4b6 "Add pubsub commands".

That patch changed the command list and one docs file. It did not touch the client, the codec or the stats code — all three are byte-identical to upstream ae1505b84c. So our fork opened a door upstream keeps shut, without adapting what is behind it.

Upstream pub/sub support is still unresolved: envoyproxy#38492 is open, and envoyproxy#46354 ("redis: add pub/sub support via RESP3 Push messages", 55 files, +15342) was closed unmerged in September. Doing it properly needs RESP3 Push frames and a per-worker subscription registry, neither of which exists in the envoy we pin.

The shape of this fix follows envoyproxy#9954, "Fix for MGET crash when upstream Redis Command Stats are enabled" — the same function, the same class of bug (a response type the code did not expect), merged at Risk Level: Low.

Scope

Dropping the frame is the conservative half: it keeps the connection alive instead of killing the proxy. Delivering pushed messages downstream is a separate problem — this decoder has no Push type at all (RespType is Null, SimpleString, BulkString, Integer, Error, Array, CompositeArray), so a pushed message cannot currently be represented, let alone routed.

The drop increments upstream_cx_protocol_error, the counter this file already uses for decoder errors, so it appears in dashboards operators watch rather than in a new stat nobody alerts on.

Operational urgency: low

redis-proxy-zone-a in dev, 27 hours uptime: command.spublish.success at 183,824 and 0 restarts. command.subscribe and ssubscribe report No recorded values. Workloads publish through the proxy but do not subscribe through it, so nothing reaches the crash today. The first service that subscribes through the proxy would hit it immediately.

Verification

The fix stops the crash. Four proxies in one pod against one redis cluster, same pubsub sequence three times:

proxy restarts after 3 rounds
v1.30.2-sendbird-custom-v0.0.2 (production) 2
v1.31.1-sendbird-custom-v0.0.1 2
v1.31.1, enable_command_stats: false 2
this branch 0

The guard is not silently passing frames through: cluster.redis_cluster.upstream_cx_protocol_error reached 7 on the patched proxy, so it caught and dropped 7 unsolicited frames while staying up.

Both regression tests pass on both architectures:

PASSED  RedisClientImplTest.UnsolicitedPushFrameWithNoPendingRequest (0.0s)
PASSED  RedisClientImplTest.UnsolicitedPushFrameWithCommandStatsEnabled (0.0s)
Executed 1 out of 1 test: 1 test passes.

Build: https://github.com/sendbird/proxy-istio/actions/runs/38621562966

A second defect this surfaced

The first attempt to run that test target failed to compile, and not because of this change:

error: field type ...ConfigBufferSizeGTSingleRequest is an abstract class
note: unimplemented pure virtual method enablePerShardStats in ConfigBufferSizeGTSingleRequest

"Add per-shard Redis proxy metrics" (0258881d) added two pure virtuals to Client::Config but changed source/ only, leaving all three Config subclasses in client_impl_test.cc abstract. That test target has not compiled since that patch landed — it is on release/v1.38.3-sendbird-custom too.

Nothing caught it because envoy CI in this fork is inherited from upstream and does not run, and the proxy-istio image build compiles source/ but no tests. The second commit here adds the missing overrides (all returning false, so no fixture measurements change).


Security checklist (Infrastructure code)

  • I have checked below conditions:
    • This PR does not contain any SecurityGroup rule changes which are not allowed via INF Jira ticket
    • This PR does not contain any public open SecurityGroup inbound rules(0.0.0.0/0) except the predefined service port
    • This PR does not contain any resources in a public subnet except those are needed with a specific technical reason
    • This PR does not contain any credentials (AWS Secret key, password, API tokens, etc)
    • This PR does not contain any IAM users which are not allowed via UAC Jira approval
    • The contents of this PR is following the guide from OSWAP and SendBird Secure Software Development Lifecycle

@jinsekim jinsekim left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

@jinsekim jinsekim added the auto-review/approved Auto-approved by pr-approver label Oct 14, 2026
@gavin-jeong
gavin-jeong changed the base branch from release/v1.39.2-sendbird-custom to CPLAT-12776-v1.39.2-sendbird-custom October 14, 2026 23:27
@gavin-jeong

Copy link
Copy Markdown
Author

Restacked the base: release/v1.39.2-sendbird-custom -> CPLAT-12776-v1.39.2-sendbird-custom. The diff went from 30 files +1130/-220 to 2 files +134/-1.

My mistake, and the same one I made on #27 earlier. I rewound release/v1.39.2-sendbird-custom to the upstream pin ae1505b84c so that PR could show only the Sendbird patches — which means a PR based on it now carries all 11 port commits as well as its own. The two approvals above were submitted against that 30-file view.

Nothing about the commits changed; both approvals are on de41db5dd7, the exact commit the build verified. But the 11 commits that were in the diff belong to #27, not here, so what you were looking at was mostly someone else is review.

The two commits that are actually this PR:

7fdb078dc2  redis: do not crash on an upstream frame with no pending request
de41db5dd7  redis test: restore the Config subclasses the per-shard patch left abstract

Merge order: #27 first, then this one. GitHub will retarget this PR to release/v1.39.2-sendbird-custom automatically when that merges.

Sorry for the second look.

@gavin-jeong

Copy link
Copy Markdown
Author

Pushed 738dd514a6, which replaces the fix with a backport of upstream's own guard. The two approvals above are on de41db5dd7 and this needs another look. Re-verification build: https://github.com/sendbird/proxy-istio/actions/runs/38668054459

Upstream already fixed this, and I missed it. The guard landed on main in envoyproxy#44936, and envoyproxy#48205 added tests for it three days ago. That PR reproduces the crash the same way we did — "a fake upstream that answers one command with two replies". So this is a backport, not an original fix, and it should look like one.

The comment in the first version was wrong. It claimed upstream could not reach this path, reasoning that subscribe is absent from upstream's command lists so no subscription can exist. That checked one way in and concluded there were none. Measured on an arm64 dev node, stock istio/proxyv2:1.31.1 — no Sendbird patches, no pub/sub — against a server that double-replies:

proxy restarts after 4 rounds
istio/proxyv2:1.31.1 (pristine upstream) 2
this branch 0

Same pod, same fake server, same command. Our pub/sub patch widens the exposure; it does not create it.

No stat is incremented any more. Upstream only logs. Keeping our counter would make this hunk a permanent fork delta on exactly the code that should dissolve the next time envoy moves, which is the point of matching the text.

The tests are now 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_. My version only checked that nothing crashed. 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.

One thing that cannot be ported: upstream drops RESP3 Push frames ahead of this check. This pin's RespType has no Push member at all.

Upstream's release branches are still affected. release/v1.36 through release/v1.39 carry the bare ASSERT, and no backport PR is open — ae1505b84c (v1.39.2-dev), the commit we pin, is in that range. The author of envoyproxy#48205 offered to open the backports if maintainers agree, so the useful contribution there is supporting evidence rather than a competing PR.

@gavin-jeong

Copy link
Copy Markdown
Author

Verification build for 738dd514a6 is green on both architectures: https://github.com/sendbird/proxy-istio/actions/runs/38668054459

arm64:  PASSED  RedisClientImplTest.UnsolicitedReplyIsDropped (0.0s)
        PASSED  RedisClientImplTest.UnsolicitedReplyIsDroppedWithCommandStatsEnabled (0.0s)
amd64:  PASSED  RedisClientImplTest.UnsolicitedReplyIsDropped (0.0s)
        PASSED  RedisClientImplTest.UnsolicitedReplyIsDroppedWithCommandStatsEnabled (0.0s)
INFO: Build completed successfully, 16988 total actions
Executed 1 out of 1 test: 1 test passes.

This re-run mattered because the change was not cosmetic: the guard stopped incrementing a counter, and both tests were rewritten with the assertion flipped from 1UL to 0UL plus upstream's stronger checks (connection stays Open, a subsequent request still completes). None of the GitHub checks on this PR compile envoy — they are Hawkman, Upwind and semgrep — so merge=ok here says nothing about whether the code builds. The proxy-istio build is the only thing that does.

Image for anyone who wants to re-run the cluster reproduction: mesg/istio/proxyv2:cplat12791-verify3 (multi-arch).

Ready to merge after #27.

Base automatically changed from CPLAT-12776-v1.39.2-sendbird-custom to release/v1.39.2-sendbird-custom October 15, 2026 06:34
ClientImpl::onRespValue assumed every frame from upstream answers a request we
sent, and read pending_requests_.front() to find it. Pub/sub breaks that: once a
connection is subscribed, the server pushes messages that answer nothing, so the
queue can be empty.

Reading front() on an empty std::list is undefined, and in release builds it
crashed three different ways depending on what was touched first. Measured on a
3-master redis cluster in dev, same pod, same cluster, three proxies differing
only in image and config:

  1.30.2, command stats on    exit 133  assert failure: search != decode_map_.end()
  1.31.1, command stats on    exit 137  OOMKilled
  1.31.1, command stats off   exit 135  Bus error

All three are this one missing check. PendingRequest::command_ is a non-owning
Stats::StatName, so with command stats on it reaches a freed symbol and
RELEASE_ASSERT in SymbolTable::fromSymbol aborts; with them off the timer and
callback references fault instead. Disabling command stats is therefore not a
workaround, which is why both paths are tested.

Reproduced with three commands: subscribe on one connection, publish on another,
wait. Not a regression from the 1.39.2 port -- the same failure happens on
release/v1.38.3-sendbird-custom, the image in production today.

Upstream envoy cannot reach this path: its supported-command lists contain no
subscribe, so the splitter rejects the command before a subscription can exist.
Pub/sub support there is still unresolved (envoyproxy#38492 open;
envoyproxy#46354 closed unmerged, 55 files, since doing it properly needs
RESP3 Push frames and a per-worker subscription registry). Our fork opened the
door by adding the commands without adapting the client, so the fix belongs here.

Dropping the frame is the conservative half: it keeps the connection alive
instead of killing the proxy. Delivering pushed messages downstream is a
separate problem -- this decoder has no RESP3 Push type at all (RespType is
Null, SimpleString, BulkString, Integer, Error, Array, CompositeArray), so a
pushed message cannot currently be represented, let alone routed. Tracked in
CPLAT-12791.

The drop is counted as upstream_cx_protocol_error, the counter this file already
uses for decoder errors, so it shows up in dashboards operators watch rather
than in a new stat nobody alerts on.
…stract

"Add per-shard Redis proxy metrics" (0258881) added two pure virtuals to
Client::Config -- enablePerShardStats and enablePerShardLatencyStats -- but
changed source/ only. The three Config subclasses in client_impl_test.cc were
never updated, so they stayed abstract and this test target has not compiled
since that patch landed:

  error: field type '...ConfigBufferSizeGTSingleRequest' is an abstract class
  note: unimplemented pure virtual method 'enablePerShardStats' in ...

Nothing caught it because envoy's CI in this fork is inherited from upstream and
does not run; the proxy-istio image build compiles source/ but no tests. The
first attempt to run this target (to exercise the CPLAT-12791 regression tests)
is what surfaced it.

All three overrides return false, including in ConfigEnableCommandStats. These
exist to make the classes concrete again, not to turn a feature on -- the tests
in that fixture assert exact counter values, so enabling per-shard stats there
would change what they measure.

Found while verifying CPLAT-12791.
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
gavin-jeong force-pushed the CPLAT-12791-redis-push-message-crash branch from 738dd51 to 1c95deb Compare October 15, 2026 06:35
@gavin-jeong
gavin-jeong merged commit 3e983d4 into release/v1.39.2-sendbird-custom Oct 15, 2026
2 checks passed
@gavin-jeong
gavin-jeong deleted the CPLAT-12791-redis-push-message-crash branch October 15, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-review/approved Auto-approved by pr-approver

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants