FIX: Ensure PresenceChannel does not raise error during readonly (#22899)
PresenceChannel configuration is cached using redis. That cache is used, and sometimes repopulated, during normal GET requests. When the primary redis server was readonly, that `redis.set` call would raise an error and cause the entire request to fail. Instead, we should ignore the failure and continue without populating the cache.
This commit is contained in:
parent
6286e790b2
commit
bb217bbcc8
|
@ -314,7 +314,10 @@ class PresenceChannel
|
||||||
else
|
else
|
||||||
raise InvalidConfig.new "Expected PresenceChannel::Config or nil. Got a #{result.class.name}"
|
raise InvalidConfig.new "Expected PresenceChannel::Config or nil. Got a #{result.class.name}"
|
||||||
end
|
end
|
||||||
PresenceChannel.redis.set(redis_key_config, to_cache, ex: CONFIG_CACHE_SECONDS)
|
|
||||||
|
DiscourseRedis.ignore_readonly do
|
||||||
|
PresenceChannel.redis.set(redis_key_config, to_cache, ex: CONFIG_CACHE_SECONDS)
|
||||||
|
end
|
||||||
|
|
||||||
raise PresenceChannel::NotFound if result.nil?
|
raise PresenceChannel::NotFound if result.nil?
|
||||||
result
|
result
|
||||||
|
|
|
@ -65,6 +65,12 @@ RSpec.describe PresenceChannel do
|
||||||
expect(channel3.count).to eq(0)
|
expect(channel3.count).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not raise error when getting channel config under readonly" do
|
||||||
|
PresenceChannel.redis.stubs(:set).raises(Redis::CommandError.new("READONLY")).once
|
||||||
|
channel = PresenceChannel.new("/test/public1")
|
||||||
|
expect(channel.user_ids).to eq([])
|
||||||
|
end
|
||||||
|
|
||||||
it "can automatically expire users" do
|
it "can automatically expire users" do
|
||||||
channel = PresenceChannel.new("/test/public1")
|
channel = PresenceChannel.new("/test/public1")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue