Defect #36395

Mailer.with_synched_deliveries is not thread-safe

Added by Holger Just about 1 year ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:


Category:Email notifications
Target version:-
Resolution: Affected version:4.2.3


The Mailer.with_synched_deliveries method sets global state (that is: the queue adapter used to queue new jobs) for the duration of the block.

This affects the global state of all concurrent threads, rather than just the current thread. If a multi-threaded application server or queueing system is in use (such as puma or resque), this can result in unintended consequences such as jobs not scheduled to the "normal" queuing system or errors being raised (if a job is supposed to be scheduled for a fixed later time which is not supported by the InlineAdapter).

As such, the method should be updated to only have a thread-local effect. This may possibly be achieved by introducing a fixed queue adapter wrapper which forwards requests to enqueue jobs to either the "normal" async adapter or the inline adapter based on a thread-local variable set by Mailer.with_synched_deliveries.

Related issues

Related to Redmine - Defect #36393: Mailer.with_synched_deliveries doesn't correctly detect o... Closed


#1 Updated by Holger Just about 1 year ago

  • Related to Defect #36393: Mailer.with_synched_deliveries doesn't correctly detect other async Queue adapters added

Also available in: Atom PDF