Skip to content

Conversation

yangy0000
Copy link

@yangy0000 yangy0000 commented Sep 13, 2025

Summary

This PR fixes an issue where encoding failures could corrupt the outstanding command queue, causing subsequent responses to be matched to wrong commands and leading to out-of-sync command/response handling.

The issue called out in #2012

Root Cause: When command encoding fails, the failed command remains in the outstanding command stack without proper cleanup, corrupting the command-response matching mechanism.

Solution:

  • Add encoding error tracking to RedisCommand interface with markEncodingError() and hasEncodingError() methods
  • Mark commands with encoding errors in CommandEncoder when encode failures occur
  • Implement lazy cleanup of encoding-failed commands in CommandHandler response processing
  • Add comprehensive unit and integration tests for encoding error scenarios

Changes Made

  • RedisCommand Interface: Added encoding error tracking methods
  • Command Class: Implemented encoding error flag with volatile boolean for thread safety
  • CommandEncoder: Mark commands on encoding failures
  • CommandHandler: Enhanced response processing to handle encoding-failed commands
  • All RedisCommand Implementations: Updated to support encoding error tracking
  • Tests: Added comprehensive unit tests (EncodingErrorHandlingTests) and integration tests (EncodingErrorIntegrationTests, CommandEncodingErrorIntegrationTests)

Test Plan

  • Unit tests covering encoding error tracking and cleanup logic
  • Integration tests simulating real encoding failure scenarios
  • Existing test suite passes
  • Manual testing with deliberate encoding failures

Fixes

This resolves command queue corruption issues that could occur when Redis commands fail during encoding, ensuring proper command-response synchronization is maintained.

Jing9 and others added 2 commits September 12, 2025 22:20
Summary:
Add encoding error tracking to prevent command queue corruption

  - Add markEncodingError() and hasEncodingError() methods to RedisCommand interface
  - Implement encoding error flag in Command class with volatile boolean
  - Mark commands with encoding errors in CommandEncoder on encode failures
  - Add lazy cleanup of encoding failures in CommandHandler response processing
  - Update all RedisCommand implementations to support encoding error tracking
  - Add comprehensive unit tests and integration tests for encoding error handling

Fixes issue where encoding failures could corrupt the outstanding command queue by leaving failed commands in the stack without proper cleanup, causing responses to be matched to wrong commands.

Test Plan: UTs, Integration testing

Reviewers: yayang, ureview

Reviewed By: yayang

Tags: #has_java

JIRA Issues: REDIS-14050

Differential Revision: https://code.uberinternal.com/D19068147
…coding failure

Summary: Fix error command handling code logic and add integration test for encoding failure

Test Plan: unittest, integration test

Reviewers: #ldap_storage_sre_cache, ureview, jingzhao

Reviewed By: #ldap_storage_sre_cache, jingzhao

Tags: #has_java

JIRA Issues: REDIS-14192

Differential Revision: https://code.uberinternal.com/D19271701
@yangy0000 yangy0000 changed the title Fix command queue corruption on encoding failuresFix encoding error command sync Fix command queue corruption on encoding failures Sep 13, 2025
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.

2 participants