Fix loading issue of ActionMailer::MessageDelivery
#32473
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I had an error
NameError (uninitialized constant #<Class:ActionMailer::Base>::MessageDelivery)
that is difficult to reproduce.I'm sending some mails in some action of ActionController using ActionMailer.
I think this is concurrency issue that is occurred when using thread-base app server like Puma.
This occurs in Rails 5.0.7 and earlier, but not occurs in Rails 5.1.0 and later.
I was using Rails 5.0.6 and Ruby 2.3.1 when this is occurred.
Before 5.0.7,
ActionMailer::MessageDelivery
is only used inActionMailer::Base#method_missing
.So,
ActionMailer::MessageDelivery
will be loaded when mail method is called.https://github.com/rails/rails/blob/v5.0.7/actionmailer/lib/action_mailer.rb#L50
https://github.com/rails/rails/blob/v5.0.7/actionmailer/lib/action_mailer/base.rb#L563
After 5.1.0,
ActionMailer::MessageDelivery
is used in the module definition ofActionMailer::Parameterized
inclueded inActionMailer::Base
.So,
ActionMailer::MessageDelivery
will be loaded when defining a class that inheritedActionMailer::Base
.https://github.com/rails/rails/blob/v5.1.0/actionmailer/lib/action_mailer.rb#L51
https://github.com/rails/rails/blob/v5.1.0/actionmailer/lib/action_mailer/base.rb#L438
https://github.com/rails/rails/blob/v5.1.0/actionmailer/lib/action_mailer/parameterized.rb#L122
I think this is similar to #27849.
Thanks.