A platform for community discussion. Free, open, simple.
FIX: during concurrent emails generation renderer should not be reused
Sam Saffron5aaf7e331675
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rbindex de8ac561eb9..28e154f8de5 100644--- a/app/mailers/user_notifications.rb+++ b/app/mailers/user_notifications.rb@@ -589,7 +589,7 @@ class UserNotifications < ActionMailer::Baseendunless translation_override_exists- html = UserNotificationRenderer.instance.render(+ html = UserNotificationRenderer.render(template: 'email/notification',format: :html,locals: { context_posts: context_posts,diff --git a/app/services/user_notification_renderer.rb b/app/services/user_notification_renderer.rbindex edf11712838..64bb497dcfb 100644--- a/app/services/user_notification_renderer.rb+++ b/app/services/user_notification_renderer.rb@@ -5,9 +5,15 @@ class UserNotificationRenderer < ActionView::Baseinclude UserNotificationsHelperinclude EmailHelper- def self.instance- @instance ||= UserNotificationRenderer.with_view_paths(- Rails.configuration.paths["app/views"]- )+ LOCK = Mutex.new++ def self.render(*args)+ LOCK.synchronize do+ @instance ||= UserNotificationRenderer.with_view_paths(+ Rails.configuration.paths["app/views"]+ )+ @instance.render(*args)+ endend+enddiff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rbindex 654c4ae3c67..df76f9170c6 100644--- a/lib/email/message_builder.rb+++ b/lib/email/message_builder.rb@@ -94,7 +94,7 @@ module Emailhtml_override.gsub!("%{respond_instructions}", "")end- html = UserNotificationRenderer.instance.render(+ html = UserNotificationRenderer.render(template: 'layouts/email_template',format: :html,locals: { html_body: html_override.html_safe }diff --git a/lib/email/renderer.rb b/lib/email/renderer.rbindex 2f9203bd6c3..feeb63c4112 100644--- a/lib/email/renderer.rb+++ b/lib/email/renderer.rb@@ -18,7 +18,7 @@ module Emailstyle = if @message.html_partEmail::Styles.new(@message.html_part.body.to_s, @opts)else- unstyled = UserNotificationRenderer.instance.render(+ unstyled = UserNotificationRenderer.render(template: 'layouts/email_template',format: :html,locals: { html_body: PrettyText.cook(text).html_safe }