FIX: do not clobber plugin store when events land fast

FIX: do not clobber plugin store when events land fast

Previously large amounts of incoming events could cause plugin store to corrupt internal state

This in turn would lead to duplicate topics

diff --git a/app/jobs/regular/process_alert.rb b/app/jobs/regular/process_alert.rb
index 05924a9..798bb28 100644
--- a/app/jobs/regular/process_alert.rb
+++ b/app/jobs/regular/process_alert.rb
@@ -6,12 +6,13 @@ module Jobs
       @token = args[:token]
       params = args[:params]
 
-      receiver = PluginStore.get(
-        ::DiscoursePrometheusAlertReceiver::PLUGIN_NAME,
-        @token
-      )
+      DistributedMutex.synchronize("prom-alert-#{@token}") do
+
+        receiver = PluginStore.get(
+          ::DiscoursePrometheusAlertReceiver::PLUGIN_NAME,
+          @token
+        )
 
-      DistributedMutex.synchronize("prom_alert_receiver_#{group_key(params)}") do
         assigned_topic(receiver, params)
       end
     end

GitHub
sha: 0343fc70

1 Like