Skip to content

Data race on RedisConnectionContext::subscribed_channels (acknowledged Fixme in connection destructor) #501

Description

@liunyl

Summary

The connection teardown path touches subscribed_channels concurrently with pub/sub operations; the code itself carries an acknowledged Fixme.

Details

src/redis_connection_context.cpp:39:

// Fixme(zkl): risk of data race for subscribed_channels

The destructor unsubscribes the connection from PubSubManager while a concurrent PUBLISH delivery (which walks subscriber lists and writes directly to sockets, src/pub_sub_manager.cpp) or a SUBSCRIBE/UNSUBSCRIBE on another bthread may access the same container.

Impact

Use-after-free / torn container state on connection close under pub/sub load — rare but crash-class.

Suggested fix

Move ownership of the subscription set fully behind PubSubManager's lock (the connection keeping only an opaque handle), or take the manager's mutex around destructor cleanup and delivery consistently.


Found during the module-docs review (#492); see docs/04-scripting-pubsub-blocking.md Gotchas.

🤖 Found with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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