Repository navigation
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
hey @insaf021 ,, thank you for reporting this. At a glance, looks like we have a bug here. |
MultiDbPipeline.sync() polled its buffered responses only after every reply had been read, so when sendCommand or getMany threw the queue was left intact and the responses stayed unset. close() calls sync(), so a pipeline in try-with-resources, or any later sync(), borrowed a fresh connection from whichever database was active by then and sent the whole batch again: non-idempotent writes ran twice, and each Response reported the replay's result as if the command had run once. Where nothing re-sent the batch, Response.get() threw IllegalStateException. Complete the buffered responses with the failure and drop the commands once the connection has been obtained, as Pipeline and ClusterPipeline do since redis#4761, so sync() and Response.get() rethrow the failure and a later sync() or close() sends nothing. A failure while borrowing the connection still leaves the batch buffered. Response.completeExceptionally is package-private, so AbstractPipeline exposes a protected helper for pipelines in other packages.
3bdeecd to
21dab52
Compare
|
Rebased onto master while you look. Nothing changed in the fix itself; since 8.1.0 shipped, the release-notes entry moved to I've also got the scripted-RESP-server reproducer that showed the batch going out twice, if a runnable repro would help the detailed read. |
Scripted RESP server that accepts the pipeline batch on the first connection and closes the socket before replying;
MultiDbClient.pipelined()in try-with-resources,INCR+RPUSH, thensync()(handshake lines trimmed):sync()threw, butclose()callssync()again and the buffered commands were still queued, so the batch went out a second time on a fresh connection, from whichever database is active by then, andincr.get()reported the replay's result. Against a real server the first batch was already applied, soINCRran twice and nothing told the caller. Where nothing re-sent the batch, the responses stayed unset andget()threwIllegalStateException: Please close pipeline or multi block before calling this method.Root cause:
MultiDbPipeline.sync()only polls its queue after every reply has been read, so a failure insendCommandorgetManyleaves it intact.PipelineandClusterPipelinealready complete their buffered responses with the failure and drop them (#4761); this does the same here once the connection has been obtained, sosync()andResponse.get()rethrow the failure and a latersync()orclose()sends nothing. A failure while borrowing the connection, before anything is written, still leaves the batch buffered.Response.completeExceptionallyis package-private, soAbstractPipelinegets a protected helper for pipelines in other packages.Two Mockito regression tests in
MultiDbPipelineUnitTestfail on master and pass here. Release-notes entry added under behaviour changes, next to the #4761 one.Note
Medium Risk
Changes error-handling semantics for experimental MultiDbPipeline; apps that relied on implicit replay via try-with-resources may see failures instead of duplicate commands, but avoids silent double-apply on partial batches.
Overview
MultiDbPipeline.sync()now matchesPipelineandClusterPipeline(#4761): if sending the batch or reading replies fails after a connection is obtained, every bufferedResponseis completed with that failure, the command queue is cleared, and a latersync()orclose()does not resend the batch (avoiding duplicate execution on another DB). Failures while borrowing the connection still leave the batch buffered for retry.A protected
AbstractPipeline.completeExceptionallyhelper exposes package-privateResponse.completeExceptionallytoMultiDbPipeline. Release notes document the behaviour change and required caller handling. Two unit tests assert no replay on write/read failure.Reviewed by Cursor Bugbot for commit 21dab52. Bugbot is set up for automated code reviews on this repo. Configure here.