Repository navigation
[CPLAT-12791] redis: do not crash on an upstream frame with no pending request - #28
Conversation
|
Restacked the base: My mistake, and the same one I made on #27 earlier. I rewound Nothing about the commits changed; both approvals are on The two commits that are actually this PR: Merge order: #27 first, then this one. GitHub will retarget this PR to Sorry for the second look. |
|
Pushed 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
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 One thing that cannot be ported: upstream drops RESP3 Upstream's release branches are still affected. |
|
Verification build for 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 Image for anyone who wants to re-run the cluster reproduction: Ready to merge after #27. |
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.
738dd51 to
1c95deb
Compare
JIRA: https://sendbird.atlassian.net/browse/CPLAT-12791
ClientImpl::onRespValueassumed every frame from upstream answers a request we sent, and readpending_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 emptystd::listis 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.v1.30.2-sendbird-custom-v0.0.2(production today)enable_command_stats: trueassert failure: search != decode_map_.end()v1.31.1-sendbird-custom-v0.0.1enable_command_stats: truev1.31.1-sendbird-custom-v0.0.1enable_command_stats: falseTwo 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-owningStats::StatName, so with command stats on it reaches a freed symbol andRELEASE_ASSERTinSymbolTable::fromSymbolaborts; 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.simpleCommandshas it 0 times upstream and 1 time here, added by our owna298a4b6"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 (
RespTypeisNull, 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-ain dev, 27 hours uptime:command.spublish.successat 183,824 and 0 restarts.command.subscribeandssubscribereportNo 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:
v1.30.2-sendbird-custom-v0.0.2(production)v1.31.1-sendbird-custom-v0.0.1v1.31.1,enable_command_stats: falseThe guard is not silently passing frames through:
cluster.redis_cluster.upstream_cx_protocol_errorreached 7 on the patched proxy, so it caught and dropped 7 unsolicited frames while staying up.Both regression tests pass on both architectures:
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:
"Add per-shard Redis proxy metrics" (
0258881d) added two pure virtuals toClient::Configbut changedsource/only, leaving all threeConfigsubclasses inclient_impl_test.ccabstract. That test target has not compiled since that patch landed — it is onrelease/v1.38.3-sendbird-customtoo.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 returningfalse, so no fixture measurements change).Security checklist (Infrastructure code)