Skip to content

Add Redis Pub/Sub bug tracking and test endpoint#85

Closed
sohankshirsagar wants to merge 1 commit intomainfrom
claude/bug-hunt-redis-V0b53
Closed

Add Redis Pub/Sub bug tracking and test endpoint#85
sohankshirsagar wants to merge 1 commit intomainfrom
claude/bug-hunt-redis-V0b53

Conversation

@sohankshirsagar
Copy link
Contributor

@sohankshirsagar sohankshirsagar commented Mar 25, 2026

Summary

This PR adds comprehensive bug tracking documentation for Redis instrumentation testing and introduces a new test endpoint that exposes a bug in Pub/Sub message handling during replay mode.

Key Changes

  • Added BUG_TRACKING.md: Comprehensive test results document covering 19 test scenarios for Redis instrumentation, including:

    • Summary of test results: 1 confirmed bug, 18 passing tests
    • Detailed descriptions of each test case with expected vs actual behavior
    • Root cause analysis for the identified Pub/Sub bug
  • Added /test/pubsub-publish endpoint: New test endpoint that demonstrates the Pub/Sub instrumentation bug:

    • Tests Redis Pub/Sub pattern with subscriber thread and publisher
    • Publishes messages through Redis.execute_command() (which is patched)
    • Subscribes through PubSub.execute_command() (which is NOT patched)
    • Includes detailed comments explaining the bug
  • Updated test_requests.py: Added call to the new Pub/Sub test endpoint in the test suite

Notable Implementation Details

The identified bug occurs because:

  • Redis instrumentation patches Redis.execute_command(), Pipeline.execute(), and their async variants
  • The PubSub class has its own separate execute_command() method that manages a persistent connection for receiving messages
  • During REPLAY mode, PubSub operations attempt real network connections instead of using mocked responses
  • This causes subscribers to receive no messages even though publishers correctly report subscriber counts

The bug affects any code that creates a PubSub subscriber within a request handler context during replay mode.

Found 1 confirmed bug: PubSub.execute_command() is not patched by the
Redis instrumentation. The PubSub class has its own execute_command()
method separate from Redis.execute_command(), so pub/sub operations
(subscribe, get_message, listen) bypass instrumentation entirely. During
replay, PubSub operations attempt real network connections which fail.

Tested 19 potential bug scenarios across all Redis data types and
patterns including: pipelines, scan iterators, blocking ops, Lua
scripts, async operations, streams, geo, sets, sorted sets, locks,
from_url clients, hash mappings, large payloads, and more. Only the
pub/sub pattern failed replay.

https://claude.ai/code/session_015MZ4GuLMi8eqzUVffB2hxa
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

def subscriber_thread():
"""Subscribe in a separate thread to receive messages."""
sub_client = redis.Redis(
host=os.getenv("REDIS_HOST", "localhost"),
Copy link

Choose a reason for hiding this comment

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

Subscriber uses wrong default Redis host

Medium Severity

The sub_client in subscriber_thread defaults to "localhost" for REDIS_HOST, while every other Redis client in this file (lines 20, 150, 185) defaults to "redis". In any environment where REDIS_HOST is not explicitly set (e.g., outside Docker), the subscriber connects to a different host than the publisher, causing message delivery to silently fail.

Fix in Cursor Fix in Web

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