Skip to content

Race condition on subscribe #933

@adrianriley

Description

@adrianriley

Looks like there is a race condition in the Jedis publish/subscribe implementation. To set up a subscription, call JedisConnection.subscribe(). That thread reads the responses from subsequent subscribe/unsubscribe commands sent on the same connection using JedisSubscription in order to maintain its view of the current subscription. But before the read on the connection's input stream, that does a flush on the output stream. See JedisPubSub.process(), which calls Connection.getObjectMultiBulkReply, which calls flush().

Another thread may concurrently be using JedisSubscription to send a command on the same stream. The result may be that the command is sent twice, or a corrupted command is sent.

To reproduce the problem, set up a subscription using JedisConnection.subscribe, then have many threads calling JedisSubscription.subscribe, JedisConnection.unsubscribe. Eventually the race condition will occur.

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