redis-rb icon indicating copy to clipboard operation
redis-rb copied to clipboard

Returning in subscription callbacks cause race condition

Open kazzix14 opened this issue 3 years ago • 0 comments

Returning in subscription callbacks cause race condition which is Redis still send us messages that are published to the channel, but redis-rb do not receive it as Pub/Sub messages. And if we use another command in that state, we get Pub/Sub messages as reply of the command.

E.g.

redis.subscribe('channel_0') do |on|
  on.message do |_channel, _message| 
    return
  end
end

# Redis still send us messages which is published to a 'channel_0'

res = redis.get('hoge')

puts res
# => ['message', 'channel_0', 'message published to a channel_0']

this could cause bugs like getting messages from chat which is not intended or getting Pub/Sub messages as a reply of other methods depends on user implementation.

kazzix14 avatar Feb 04 '22 16:02 kazzix14