Skip to content

Race condition bug in async Redis cluster pipeline #2304

@karwinliu

Description

@karwinliu

Version: v4.3.4

Platform: Python 3.9 on linux/macOS

Description: When multiple pipelines are happening in parallel (e.g. running with asyncio or trio), it's possible to trigger a race condition where the last pipeline would clear up all the queued commands in the stack from other pipelines. The code that has issue is in redis/asyncio/cluster.py file,

node = target_nodes[0]
if node.name not in nodes:
    nodes[node.name] = node
    node._command_stack = []
node._command_stack.append(cmd)

All the pipelines seem to share the same node._command_stack, and one could overwrite the others before the commands get sent out. We've seen this issue in our code consistently. We've locally patched the code to maintain a command stack per pipeline instead of per node and that seems to have fixed the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions