Rails Stack Level too deep - ruby-on-rails

How can I get more information from an error like this?
=> Booting WEBrick
=> Rails 3.1.1 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
script/rails:6: stack level too deep (SystemStackError)

The error was only occurring in production.
When changing settings inside config/environments/production.rb, I found that setting config.cache_classes = false let me boot the app in production. Upon reviewing the commit I found the offending class.
I had created a model called Object which seemed to have interfered with the way caching works, likely overwriting a core ruby Object class.

It's a loop. To have more details of this, you et "config.log_level = :debug" in the config/environments/production.rb and restart your server

Related

How to run an initializer that calls Rails.application?

I've seen posts where the suggestion was to create an initializer or create a config.after_initialize block in the config/application.rb file; however, this doesn't properly work for me because I'm relying on Rails credentials.
For example, I have a class called SlackBot that basically sends a message to our slack channel. I'd like to create an initializer that sends a message once the rails s command is run, but the config.after_initialize doesn't actually work since the SlackBot class pulls creds from Rails.application.credentials
I get the following error when trying to do this:
ubuntu#bf29b8edfeea:~/myapp$ rails s --binding 0.0.0.0 -p 80
=> Booting Puma
=> Rails 6.1.4.4 application starting in development
=> Run `bin/rails server --help` for more startup options
Exiting
/usr/local/bundle/gems/activesupport-6.1.4.4/lib/active_support/message_verifier.rb:176:in `verify': ActiveSupport::MessageVerifier::InvalidSignature (ActiveSupport::MessageVerifier::InvalidSignat
ure)
from /usr/local/bundle/gems/activesupport-6.1.4.4/lib/active_support/message_encryptor.rb:154:in `decrypt_and_verify'
from /usr/local/bundle/gems/activesupport-6.1.4.4/lib/active_support/messages/rotator.rb:22:in `decrypt_and_verify'
from /home/ubuntu/myapp/app/helpers/user_helper.rb:19:in `decrypt_data'
The only way I can get rid of this error of course is by removing the custom initializer.
Is there a way that I can call an initializer or method after rails is fully initializer, perhaps as the last step that runs?
According to The Rails Initialization Process of the Rails official reference, the last file to be executed in the initialization sequence is config/environment.rb (Note that although the reference states the last one is config/application.rb, the file should have been in default require-d in the earlier process).
In Rails 6 (or maybe earlier ones, too?), the last line in config/environment.rb is
Rails.application.initialize!
So, if you write your own statements after the line in the file config/environment.rb, your Rails app must have been fully initialized by the time your statements are executed.

Why does my WEBrick server get killed?

I've got a rails development environment running in DigitalOcean on Ubuntu 12.04, but my WEBrick process keeps getting "killed" after a couple of hours. I haven't been able to find any settings or configuration that would cause this.
Example Console Ouput:
user#machinename:~/git/app$ rails s
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2014-01-05 09:14:29] INFO WEBrick 1.3.1
[2014-01-05 09:14:29] INFO ruby 2.0.0 (2013-11-22) [x86_64-linux]
[2014-01-05 09:14:29] INFO WEBrick::HTTPServer#start: pid=23452 port=3000
Started GET "/" for x.x.x.x at 2014-01-05 09:14:37 +0000
Processing by FunController#welcome as HTML
...
The server and app run just fine when I'm using it. But, at some point, my server will quit working. And, I'll look at the console to see this output from WEBrick:
Killed
And kick me back out to the shell. Any ideas what is causing this?
It runs out of memory. The linux kernel kills it. Droplets don't come with any 'swap' by default, so when the memory gets full, it kills a process or won't let you start a new one. Kinda crazy.
Here's an article walking you through adding a swapfile:
https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04
Note: I still had some problems with compiler processes being 'killed' even after adding a swapfile when 'swappiness' was set to 0. Upping it to 20 fixed the problem.
Note2: You really shouldn't use webrick in production as others have mentioned in the comments. Still, a question is a question :)

Rails server not starting with web sockets and redis options in rake task.

I have to use websockets in my rake task and for that I changed my event.rb to
config.synchronize = true
# Uncomment and edit to point to a different redis instance.
# Will not be used unless standalone or synchronization mode
# is enabled.
config.redis_options = {:host => 'localhost', :port => '3000'}
and when I start my rails server I get this error:
! Invalid request
Exiting
/usr/local/rvm/gems/ruby-1.9.3-p194#socialmail/gems/redis-3.0.4/lib/redis/connection/synchrony.rb:115:in `read': Got 'Protocol error, got "H" as reply type byte' as initial reply byte. If you're in a forking environment, such as Unicorn, you need to connect to Redis after forking. (Redis::ProtocolError)
What am I doing wrong?
Thanks
Hey thanks for the question, I personally couldn't get a rake task of mine to post to a websocket channel I had open on my rails server. Your synchronize command helped (along with starting a Redis server locally).
Your problem through - seems like you're pointing to 3000. Is that your rails server or the Redis instance? If you're running it locally, I'd omit that line.

Aptana Studio: A server is already running error

Sometimes when I boot up my computer then open up Aptana Studio for Rails, then try to start my server, I get the following error...
=> Booting WEBrick
=> Rails 3.2.11 application starting in development on http://localhost:3000
=> Call with -d to detach
A server is already running. Check C:/Users/bob/bob_rails_demo/Course_Stats/tmp/pids/server.pid.
=> Ctrl-C to shutdown server
Exiting
When I check that file metioned, I open the file and all it says inside the file is ...
512
Is there a fix for this? I don't see anything else running in task manager. BTW I am running rails 3.2.11 w/ Windows 7.
I have the same problem too, and it didn't happen before, so i believe it is some kind of bug. What I do to solve it is simply delete the server.pid at C:[pathToApp]\tmp\server.pid file before starting my server.
It is saying that PID (process id) 512 is running the server.
Go to Start -> then type taskmgr.exe. Then, go to the processes tab and look for that process and kill it. It might be a bug that it does not close the server correctly on exit.

Not getting debug output for view errors in development mode

This is very odd. At the moment, I have some kind of error in a view, but can't see what it is. Also, no debug output in the web server trace.
The Rails 3.2.2 app is an upgrade from 2.7.10, and I'm using "thin" as my development server. I do get normal debug output when the error occurs in other places.
EDIT: I'm running development, as you can see here:
=> Booting Thin
=> Rails 3.2.2 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
EDIT: I can duplicate this behavior by raising an exception in the controller.
Please check you development.rb and ensure that
config.consider_all_requests_local = true
Otherwise exceptions and stack traces will not be shown.
I would compare the files in your ./config directory of your app with those of a clean Rails 3.2 install. They've restructured things pretty significantly and there are often strange errors like this that popup if you don't properly upgrade all the config files.

Resources