几天前,我们在从Rails应用程序发送电子邮件时开始面临问题。 以下是错误的回溯:
mail-2.4.4/lib/mail/body.rb:143→ get_best_encoding
mail-2.4.4/lib/mail/body.rb:156→ encoded
mail-2.4.4/lib/mail/message.rb:1710→ encoded
actionmailer-3.2.8/lib/action_mailer/base.rb:434→ set_payload_for_mail
actionmailer-3.2.8/lib/action_mailer/base.rb:414→ block in deliver_mail
activesupport-3.2.8/lib/active_support/notifications.rb:123→ block in instrument
activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20→ instrument
activesupport-3.2.8/lib/active_support/notifications.rb:123→ instrument
actionmailer-3.2.8/lib/action_mailer/base.rb:413→ deliver_mail
mail-2.4.4/lib/mail/message.rb:229→ deliver
!===> app/controllers/password_resets_controller.rb:16→ create <===!
actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb:4→ send_action
actionpack-3.2.8/lib/abstract_controller/base.rb:167→ process_action
我突出显示了指向我们代码的行。其余的是gem / rails代码。 值得注意的是,在这种环境下,我们会通过delayed_job发送一些电子邮件,而其他一些电子邮件则不会发送。上面的堆栈跟踪是指没有delayed_job发送的电子邮件。
我们已经能够在我们应用了以下更改的开发环境中重现该问题:
以下是开发环境中错误的回溯:
mail (2.4.4) lib/mail/body.rb:143:in `get_best_encoding'
mail (2.4.4) lib/mail/body.rb:156:in `encoded'
mail (2.4.4) lib/mail/message.rb:1710:in `encoded'
actionmailer (3.2.9) lib/action_mailer/base.rb:434:in `set_payload_for_mail'
actionmailer (3.2.9) lib/action_mailer/base.rb:414:in `block in deliver_mail'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.9) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.9) lib/active_support/notifications.rb:123:in `instrument'
actionmailer (3.2.9) lib/action_mailer/base.rb:413:in `deliver_mail'
mail (2.4.4) lib/mail/message.rb:229:in `deliver'
delayed_job (3.0.4) lib/delayed/performable_mailer.rb:6:in `perform'
delayed_job (3.0.4) lib/delayed/backend/base.rb:95:in `block in invoke_job'
delayed_job (3.0.4) lib/delayed/lifecycle.rb:60:in `call'
delayed_job (3.0.4) lib/delayed/lifecycle.rb:60:in `block in initialize'
delayed_job (3.0.4) lib/delayed/lifecycle.rb:65:in `call'
delayed_job (3.0.4) lib/delayed/lifecycle.rb:65:in `execute'
delayed_job (3.0.4) lib/delayed/lifecycle.rb:38:in `run_callbacks'
delayed_job (3.0.4) lib/delayed/backend/base.rb:92:in `invoke_job'
delayed_job (3.0.4) lib/delayed/backend/base.rb:37:in `block in enqueue'
delayed_job (3.0.4) lib/delayed/backend/base.rb:36:in `tap'
delayed_job (3.0.4) lib/delayed/backend/base.rb:36:in `enqueue'
delayed_job (3.0.4) lib/delayed/message_sending.rb:13:in `method_missing'
!===> app/controllers/password_resets_controller.rb:16:in `create' <===!
actionpack (3.2.9) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.9) lib/abstract_controller/base.rb:167:in `process_action'
据我们所知,除了delayed_job部分和gem版本之外,它似乎是完全相同的堆栈跟踪。
我们的应用程序控制器的第16行在我们的开发环境中如下所示:
UserMailer.delay(:queue => "mail").password_reset_instructions(@user)
在prod中它是:
UserMailer.password_reset_instructions(@user).deliver
棘手的部分是这个bug是“随机的”。它不会每次都发生,当它没有发生时,邮件会成功发送。
以下是两个观察结果:
我们一直在调查这个漏洞几天,但我们真的在这里碰壁了。你知道我们可能做错了什么吗?