-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
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.