You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In our application we store each email attempt/delivery inside a table for tracking purposes, and I was surprised that deliver_all_later was taking a lot of time to send around 2000 emails. after looking at the logs i figured that all mailers were processed as if i was calling deliver_now
Additional information
@fatkodima I still don't know why by looking at this caller stack, but it seems flatten! eager load the mails by trying to delegate a method which triggers the inline processing here:
Here is the `callers` output
```
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/gems/sentry-rails-5.26.0/lib/sentry/rails/tracing.rb:56:in 'Sentry::Rails::Tracing::SentryNotificationExtension#instrument'",
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/activesupport/lib/active_support/notifications.rb:210:in 'ActiveSupport::Notifications.instrument'",
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/base.rb:651:in 'ActionMailer::Base#process'",
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:170:in 'block in ActionMailer::MessageDelivery#processed_mailer'",
":91:in 'Kernel#tap'",
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:169:in 'ActionMailer::MessageDelivery#processed_mailer'",
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:66:in 'ActionMailer::MessageDelivery#__getobj__'",
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/3.4.0/delegate.rb:101:in 'Delegator#respond_to_missing?'",
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:23:in 'respond_to?'",
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:23:in 'Array#flatten!'",
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:23:in 'ActionMailer._deliver_all_later'",
"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:10:in 'ActionMailer.deliver_all_later'",
</details>
I can't figure out how this line is called `"/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:23:in 'respond_to?'"`
when calling `flatten!` at line 23, it tries to call `respond_to?`
### Checklist
Before submitting the PR make sure the following are checked:
* [x] This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
* [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]`
* [x] Tests are added or updated if you fix a bug or add a feature.
* [ ] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.
The reason will be displayed to describe this comment to others. Learn more.
thanks for merging @fatkodima . But sorry if you don't mind i'm going to add back at least the test where we pass an array to properly test if deliveries.first.is_a?(Array)
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.
Motivation / Background
This Pull Request has been created to fix #55658
Detail
In our application we store each email attempt/delivery inside a table for tracking purposes, and I was surprised that
deliver_all_later
was taking a lot of time to send around 2000 emails. after looking at the logs i figured that all mailers were processed as if i was callingdeliver_now
Additional information
@fatkodima I still don't know why by looking at this caller stack, but it seems
flatten!
eager load the mails by trying to delegate a method which triggers the inline processing here:rails/actionmailer/lib/action_mailer/message_delivery.rb
Lines 65 to 67 in aedfc4a
Here is the `callers` output
``` "/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/gems/sentry-rails-5.26.0/lib/sentry/rails/tracing.rb:56:in 'Sentry::Rails::Tracing::SentryNotificationExtension#instrument'", "/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/activesupport/lib/active_support/notifications.rb:210:in 'ActiveSupport::Notifications.instrument'", "/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/base.rb:651:in 'ActionMailer::Base#process'", "/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:170:in 'block in ActionMailer::MessageDelivery#processed_mailer'", ":91:in 'Kernel#tap'", "/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:169:in 'ActionMailer::MessageDelivery#processed_mailer'", "/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:66:in 'ActionMailer::MessageDelivery#__getobj__'", "/Users/user/.rbenv/versions/3.4.5/lib/ruby/3.4.0/delegate.rb:101:in 'Delegator#respond_to_missing?'", "/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:23:in 'respond_to?'", "/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:23:in 'Array#flatten!'", "/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:23:in 'ActionMailer._deliver_all_later'", "/Users/user/.rbenv/versions/3.4.5/lib/ruby/gems/3.4.0/bundler/gems/rails-d18731bed119/actionmailer/lib/action_mailer/message_delivery.rb:10:in 'ActionMailer.deliver_all_later'",