Skip to content

Fix reply alignment after skip-result batches - #7445

Open
rahulrane50 wants to merge 5 commits into
redisson:masterfrom
rahulrane50:rahul_rane--fix-skip-result-reply-boundary
Open

rahulrane50 wants to merge 5 commits into
redisson:masterfrom
rahulrane50:rahul_rane--fix-skip-result-reply-boundary

Conversation

@rahulrane50

@rahulrane50 rahulrane50 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

A Redis-queued skipResult() batch can finish decoding after only CLIENT REPLY OFF's QUEUED reply when responses are fragmented, leaving EXEC to time out. Batch decoding also needs to preserve reply boundaries when subsequent commands' replies arrive in the same read.

Determine whether reply suppression took effect and retain that decision for the lifetime of the batch. Frame only the remaining replies after a resumed decode, including queued transactions and optional WAIT/WAITAOF responses. Preserve an earlier command error across resumes and use the same remaining boundary for late replies to completed batches.

When Redis rejects CLIENT REPLY OFF, decode the unsuppressed command replies. In-memory batches whose writes succeeded still succeed with empty results; rejection of the internal OFF/ON optimization does not report already executed writes as failed. Actual command errors still fail the batch. For in-memory atomic fallback, align EXEC results with the commands following MULTI.

Log one WARN per refused OFF with the Redis rejection reason and the disabled optimization. The corresponding ON refusal does not emit a duplicate warning. Replace CR/LF with underscores in the logged reason to prevent untrusted Redis text from injecting log lines; retain the original text in the exception cause. For Redis-queued transactions, retain the OFF rejection across resumed decoding and attach it as the cause of EXECABORT before completing the EXEC future exceptionally. Callers retain both the transaction failure and the original ACL or renamed-command reason.

Validation with JDK 25 and Redis 8.10:

  • All 63 deterministic batch decoder cases pass. Coverage includes coalesced following commands, byte fragmentation, queued and atomic batches, synchronization, and completed batches. Resume tests return after a complete first reply through the protected decoder entry point, then resume with its checkpointed state. Logging assertions check exactly one WARN for refused OFF, no duplicate for ON, and no warning for successful suppression. Exception assertions cover the retained cause across resumes and an unrelated replica rejection with no artificial cause.
  • All 10 added real-Redis integration cases pass. They cover genuine reply fragmentation, ACL denial of client|reply, a renamed CLIENT, and a node becoming a replica before EXEC. Rejection tests check non-idempotent writes execute exactly once, following string/integer reads stay aligned, and real command errors remain visible. Queued callers now assert both the EXECABORT exception and the original refusal as its root cause.
  • A negative control on published decoder/state 8ab3c1fda49a7 fails 14 of the 22 selected warning/cause cases, including both real-Redis queued refusal cases. The revision passes all 22.
  • The previous wider focused run passed 96 of 97 cases without automatic retries. Existing testAtomicSyncSlaves variant 1 expected one replica acknowledgment and received zero. A fresh control on unmodified base 64d5fbf7c73e9 reproduces that same failure; variant 2 passes in both runs.
  • The latest targeted run passes all 88 cases (63 batch decoder cases, 15 other decoder cases, and 10 Redis integration cases). The four adversarial line-break cases fail on the previous logging code and pass with sanitization, including verification that the original queued transaction cause is preserved. These cases inject untrusted server bytes to test the logging boundary; they are not presented as normal Redis responses.
  • Checkstyle and license checks pass.

The genuine fragmented REDIS_WRITE_ATOMIC reproduction fails on unmodified base 64d5fbf7c73e9, using its normal heartbeat implementation and no injected PING. Both in-memory fragmentation cases pass on that base. testSkipResultWhenNodeBecomesReplicaBeforeExec also passes on the base and is retained as compatibility coverage, not evidence of a new regression.

Related to #7380.

@mrniko

mrniko commented Nov 19, 2026

Copy link
Copy Markdown
Member

Can you add a test to RedissonBatchTest too?

@mrniko mrniko added this to the 4.9.0 milestone Nov 19, 2026
@mrniko mrniko added the bug label Nov 19, 2026

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

if CLIENT REPLY OFF has no effect, the commands after the batch get incorrect replies

reply is broken for: ACL user without client|reply, or a renamed CLIENT command, REDIS_WRITE_ATOMIC batch with skipResult(), and the node becomes a replica before EXEC.

testFailedSkipResultBatchPreservesFollowingReply incorrect. This test sends -ERR rejected batch and then +PONG. Redis cannot send this sequence for this batch. If CLIENT REPLY OFF has an effect, Redis sends no error reply. If Redis refuses it, Redis sends a reply for each command.

@rahulrane50

Copy link
Copy Markdown
Contributor Author

@mrniko updated PR and addressed your comments. PTAL

@rahulrane50
rahulrane50 requested a review from mrniko November 20, 2026 20:21
@rahulrane50

Copy link
Copy Markdown
Contributor Author

@mrniko gentle ping.

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

In IN_MEMORY and IN_MEMORY_ATOMIC mode, if Redis refuses CLIENT REPLY OFF, the batch now fails with NOPERM. But Redis ran all commands of the batch. testSkipResultWhenClientReplyIsRejected shows this: the batch fails, and rejected:key contains "value".

If the decoder starts again in the middle of a batch, isResultSkipped() reads a later reply as the first reply.

testSkipResultWhenNodeBecomesReplicaBeforeExec passes without changes applied.

@rahulrane50

Copy link
Copy Markdown
Contributor Author

Good catch @mrniko updated PR.

@rahulrane50
rahulrane50 requested a review from mrniko November 24, 2026 23:35
@rahulrane50

Copy link
Copy Markdown
Contributor Author

@mrniko whenever you have time can you take a look at updated PR once. Thanks!

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

Add a log when OFF is refused. One WARN would tell that the optimization is off, and that the ACL is the reason.

When OFF is refused inside MULTI, Redis always aborts EXEC. The caller now gets only EXECABORT Transaction discarded because of previous errors. The NOPERM that caused it is skipped.

String reason = readString(in, StandardCharsets.US_ASCII);
state.setReplyOffError(new RedisException(reason));
log.warn("CLIENT REPLY OFF was refused; batch reply suppression is disabled. channel: {}, reason: {}",
channel, reason.replaceAll("[\\r\\n]", "_"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants