A platform for community discussion. Free, open, simple.
FIX: Ensure PresenceChannel does not raise error during readonly (#22899)
David Taylorbb217bbcc8c9
diff --git a/lib/presence_channel.rb b/lib/presence_channel.rbindex 091f9ec053f..21da97d5b4d 100644--- a/lib/presence_channel.rb+++ b/lib/presence_channel.rb@@ -314,7 +314,10 @@ class PresenceChannelelseraise InvalidConfig.new "Expected PresenceChannel::Config or nil. Got a #{result.class.name}"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)+ endraise PresenceChannel::NotFound if result.nil?resultdiff --git a/spec/lib/presence_channel_spec.rb b/spec/lib/presence_channel_spec.rbindex acf2b44652e..be6e28fc1cb 100644--- a/spec/lib/presence_channel_spec.rb+++ b/spec/lib/presence_channel_spec.rb@@ -65,6 +65,12 @@ RSpec.describe PresenceChannel doexpect(channel3.count).to eq(0)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" dochannel = PresenceChannel.new("/test/public1")