# Rails 2.0.1 initializer weird infinite loop situation

**URL:** <https://www.ruby-forum.com/t/rails-2-0-1-initializer-weird-infinite-loop-situation/122526>\
**Category:** Rails\
**Created:** [December 8, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/rails-2-0-1-initializer-weird-infinite-loop-situation/122526 "2007-12-08T20:04:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptontiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@ptontiger](https://www.ruby-forum.com/u/ptontiger)\
**Post date:** [December 8, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/rails-2-0-1-initializer-weird-infinite-loop-situation/122526/1 "2007-12-08T20:04:26Z")

</div>

Just switched an app over from 1.2 to 2.0.  
In accordance with the new convention, I moved my custom configuration  
information out of config/environment.rb and into config/initializers/  
app\_config.rb. I found that my actionmailer config block was causing  
an infinite loop (encompassing more than just the block itself).  
Nothing like this happened with 1.2.x. Here’s the code (nothing  
special):

DOMAIN\_NAME = ‘[example.com](http://example.com)’

# Uses lib/smtp\_tls.rb (Gmail SSL SMTP requires this)

Rails::Initializer.run do |config|  
config.action\_mailer.perform\_deliveries = false # For now

# config.action\_mailer.perform\_deliveries = true

config.action\_mailer.raise\_delivery\_errors = true  
config.action\_mailer.delivery\_method = :smtp  
config.action\_mailer.default\_charset = :‘utf-8’  
config.action\_mailer.smtp\_settings = {  
:address =\> ‘[smtp.gmail.com](http://smtp.gmail.com)’,  
:port =\> 587,  
:domain =\> DOMAIN\_NAME,  
:authentication =\> :plain,  
:user\_name =\> ‘mailer@’ + DOMAIN\_NAME,  
:password =\> ‘secret’  
}  
end

# …

As is, Rails won’t load and a never ending train of warnings about an  
already initialized constant DOMAIN\_NAME shows in the console  
(evidence that the infinite loop encompasses more than the block). lib/  
smtp\_tls.rb is not the source of the problem and neither is the  
declaration of the constant.

There are two ways to fix this as far as I know - comment out the  
block and skip the configuration or put ‘break’ before ‘end’.

Any ideas on what’s behind this?

---

<div class="post-metadata">

**Author:** ![ptontiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@ptontiger](https://www.ruby-forum.com/u/ptontiger)\
**Post date:** [December 8, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/rails-2-0-1-initializer-weird-infinite-loop-situation/122526/2 "2007-12-08T20:18:28Z")

</div>

On 8 Dec 2007, at 19:03, ptontiger wrote:

> :domain =\> DOMAIN\_NAME,  
> :authentication =\> :plain,  
> :user\_name =\> ‘mailer@’ + DOMAIN\_NAME,  
> :password =\> ‘secret’  
> }  
> end

That’s causing the initializer to be run again from your initializer  
file, which loads your initializer file, which runs the initializer  
again …

Fred

---

<div class="post-metadata">

**Author:** ![ptontiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@ptontiger](https://www.ruby-forum.com/u/ptontiger)\
**Post date:** [December 8, 2007, 8:23pm UTC](https://www.ruby-forum.com/t/rails-2-0-1-initializer-weird-infinite-loop-situation/122526/3 "2007-12-08T20:23:10Z")

</div>

Thanks Fred, that makes perfect sense. That being the case, how would  
I inject this configuration information into the mix then?

On Dec 8, 2:17 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ptontiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@ptontiger](https://www.ruby-forum.com/u/ptontiger)\
**Post date:** [December 8, 2007, 8:56pm UTC](https://www.ruby-forum.com/t/rails-2-0-1-initializer-weird-infinite-loop-situation/122526/4 "2007-12-08T20:56:40Z")

</div>

On 8 Dec 2007, at 19:22, ptontiger wrote:

> Thanks Fred, that makes perfect sense. That being the case, how would  
> I inject this configuration information into the mix then?

I think that sort of stuff is fine to stay in environment.rb -  
basically it’s not about  
extracting stuff from the Rails::Initializer.run do |config| block but  
about all the stuff at the bottom.

Fred

---

<div class="post-metadata">

**Author:** ![ptontiger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@ptontiger](https://www.ruby-forum.com/u/ptontiger)\
**Post date:** [December 8, 2007, 9:01pm UTC](https://www.ruby-forum.com/t/rails-2-0-1-initializer-weird-infinite-loop-situation/122526/5 "2007-12-08T21:01:56Z")

</div>

Will do. Thanks for the advice.

On Dec 8, 2:55 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
