0

I have a problem running radiant mailer extension SystemStackError in SiteController#show_page on any page, which doesn't contain mailer functionality. I've found, that that there is a module that casus issues:

Module MailerProcess
  include RecaptchaMailer

  def self.included(base)
    base.class_eval {
      alias_method_chain :process, :mailer
      attr_accessor :last_mail
    }
  end

  def process_with_mailer(request, response)
    # If configured to do so, receive and process the mailer POST
    if Radiant::Config['mailer.post_to_page?'] && ... 
       # here process_mail from RecaptchaMailer called - works fine 
    end
    process_without_mailer(request, response)
  end
end

And here process_without_mailer is what completely confuses me - there is no such definition. THis method actually causes lots of "SHOW TABLES" in logs and finally the exception. This method i suspect is some more or less Rails part, bcause there are the same calls e.g. in actionpack-2.3.18/lib/action_controller/filters.rb (process_without_filters), rails-4.0.0/guides/source/active_support_core_extensions.md (process_without_stringified_params) - those methods also don't have any definitions.

So, there are two questions:

  1. why process_with_mailer is called during any page load?
  2. what's the magic behind process_without_mailer?

UPD:

ok, commenting out method process_with_mailer gives error during startup:

/home/sab/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-2.3.18/lib/active_support/core_ext/module/aliasing.rb:34:in `alias_method': undefined method `process_with_mailer' for class `Page' (NameError)
        from /home/sab/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-2.3.18/lib/active_support/core_ext/module/aliasing.rb:34:in `alias_method_chain'
        from /home/sab/_work/radiant-cms/vendor/extensions/mailer/lib/mailer_process.rb:6:in `block in included'
        from /home/sab/_work/radiant-cms/vendor/extensions/mailer/lib/mailer_process.rb:5:in `class_eval'

So, probably alias_method_chain causes calling method every page load, but mechanics is unclear to me. I've found some ActiveSuppor doc.

UPD2 well i ended up with

  1. Reading Ruby on Rails: alias_method_chain, what exactly does it do?
  2. commenting out process_with_mailer and alias_method_chain. on that configuration it sends emails, so that's acceptable. i still would like to know, what was author's general idea.
Community
  • 1
  • 1
sab
  • 651
  • 8
  • 17
  • By looks of it, `process_with_mailer` is stuck in infinite recursive loop causing it to blow stack. can you commentout the recurive call & see it the error persists? – CuriousMind Aug 29 '13 at 11:38
  • @Gaurish Commenting `process_without_mailer` causes: `ERROR TypeError: can't convert Array into String .../ruby-1.9.3-p448/gems/rack-1.1.6/lib/rack/handler/webrick.rb:61:in `block in service' .../ruby-1.9.3-p448/gems/actionpack-2.3.18/lib/action_controller/response.rb:155:in `each' .../ruby-1.9.3-p448/gems/actionpack-2.3.18/lib/action_controller/response.rb:155:in `each' .../ruby-1.9.3-p448/gems/actionpack-2.3.18/lib/action_controller/string_coercion.rb:16:in `method_missing' .../ruby-1.9.3-p448/gems/actionpack-2.3.18/lib/action_controller/reloader.rb:22:in `method_missing'` – sab Aug 29 '13 at 11:54

1 Answers1

0

Read the article about alias_method_chain again, until you really get it. That is indeed what triggers process_with_mailer every time process is called.

By commenting out process_with_mailer and alias_method_chain, you essentially broke this code as it will never trigger again. The reason that emails are now being sent, is because the mailer extension can be set up in two ways;

  • if Radiant::Config['mailer.post_to_page?'] is true, mailer forms will post to the current url. E.g. it will POST to domain.tld/contact, then Radiant finds the page at that path, and processes it. Thanks to the alias_method_chain, it will find out if the form has just been posted, and then do it's thing to actually send the mail.
  • if Radiant::Config['mailer.post_to_page?'] is not true (or not set), the contact form will POST to something like domain.tld/pages/:id/mail. That request is not handled by Radiant's SiteController, but by the MailController, which does not use process_with_mailer. The second is apparently your case, as you say that emails are properly sent now after commenting out the alias_method_chain.

Exactly what caused the SystemStackError is hard to say without a more complete error message, but: judging from something you pasted (activesupport-2.3.18), you are trying to use this extension with radiant 1.1.3, while it has not been updated in 4 years.. Do you actually use the recaptcha functionality? If not, I'd say drop this fork and use the 'normal' mailer extension that it is based on: https://github.com/radiant/radiant-mailer-extension

  • great answer, thx! you've confirmed my suspicions that by commenting this part i'll loose ability to post with a better url than /pages/id/mail. you are correct i'm using recapthca fork actually, i've also tested with clean mailer extension, where the stack overflow persists as well. it wasn't updated for a year or two as well... still, i need captcha and i see it is in fact two or three lines of code that differ, so i could modify the 'normal' branch if it was in better state. – sab Aug 29 '13 at 22:46
  • I use the mailer extension regularly and can assure you that it still works fine in the latest 1.x releases of Radiant. Perhaps you need to look for the cause elsewhere.. i.e. do you have a valid 'mailer' part etc.? Could you post the entire error you get? – Benny Degezelle Aug 30 '13 at 10:54
  • unfortunately, have no time to reproduce it again, so i'll accept the answer since it really points tthe direction for investigation – sab Sep 09 '13 at 23:32