rails console doesn't load - ruby-on-rails

Today, for no reason, my rails(2.1.0) application is very slow or even not responding.
It happens intermittently.
So sometimes it works but again it doesn't work.
When it doesn't work, I can't even load 'script/console production'.
I want to know where it's stuck.
How do I load console step-by-step so that I can know which part causes the problem?
Thanks.
Sam

You could be running out of memory on your server and so the machine can't respond to you. If you are running mongrel then get monit onto it to limit the memory it can use and restart where necessary.
If you are using Passenger, try limiting the amount of instances, and if you have already done that look up a script that kills passenger instances when too big via a cron job.
If it's not a memory issue then I'd probably need more information.

If you are able, try temporarily removing all plugins/gems and see if the app will boot. One of those is likely the problem.
The script/console file contains this.
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'
You can find the commands/console file here for Rails 2.1.
I recommend loading up irb and trying to load your app from there.
require 'config/boot'
If that works, then try stepping through the rest of the mentioned commands/console script to find out which part is the problem.
If the boot file won't load, take a look at that config/boot.rb file to see if you can determine which part isn't working. Good luck!

When all else fails, you should be able to use strace to debug what the script/application is actually doing. Note that this should only be one of the last resorts as it produces extremely verbose information (and also mostly limited to I/O actions).
Try using 'strace script/console production' for example

Related

How can I find out what prevents a rails app from loading a page?

I have a rails which seemed to be working previously but now after some changes when I go to the root page it takes it infinitely to load it, it just doesn't load it. There're nothing useful in the console either. How can I find out what prevents it from loading the main page? Is it about profiling?
Check your Rails logs, eg. development.rb. You can put logger.info, or puts statements in your environment.rb, development.rb and application.rb files to see how far Rails is getting in the boot process. You can also create a dumb initializer named 00_start_init.rb with a logger.info or puts statement to see if you're getting as far as initialization. I've found that useful before.
To really understand where you application is hanging, you need to understand the Rails initialization process. Here is the documentation for Rails version 4.2. http://guides.rubyonrails.org/v4.2/initialization.html. Similar documentation exists for every version of Rails. You can take advantage of understanding the boot sequence by placing log statement at various point in the process.
I'm assuming you're in the development environment. If so, and the console loads, it's likely not a configuration problem. It's more likely a problem with your controllers or models. If the console won't load to a prompt, then it's likely a configuration problem in application.rb, development.rb, an initializer, etc.
You mention profiling, but provide no details about it. I can't even guess what you're referring to, so the answer is "maybe?". If you can post the code changes you made since the app last loaded in the browser, that would make it much easier to help you trouble-shoot.

Is there a reliable tool for stepping through code while serving in foreman

I'm looking for some suggestions on a tool similar to using binding.pry.
I'm serving a rails app locally with foreman and would like to accomplish the same ability to put "debuggers" in my code and when the process hits that, freeze and open a console environment in that section of the code.
I've tried using pry with foreman to no avail and was curious if there are other known tools I'm not finding through google?
Thanks for the suggestions.
Try pry-remote, it seems to be the answer of running Pry with Foreman.
Checklist:
Make sure you're using binding.remote_pry instead of binding.pry.
Make sure to run your program making binding.remote_pry first and then run in console remote-pry, otherwise the pry server won't be running.
If nothing helps, try adding require 'pry-remote' at the top of your .rb file.
Check also this issue.

How to find out why rails server hangs at 100%?

Can someone think of a way to find out where our rails production server hangs? Its CPU is at 99% so I assume it gets lost in a while/for/each loop. Unfortunately we can't find a candidate loop.
The problem does not occur in development and our test suit now has 100% code coverage.
We were already attaching to Ruby via gdb, but didn't know where to go from there.
Any ideas?
Once you have attached with gdb to the busy looping process then call rb_backtrace from gdb:
> call rb_backtrace()
The output from rb_backtrace will be similar to a crash report, and the output will go to your log files similar to a standard Ruby error backtrace.
From there you should hopefully already be a step closer to the solution since you will see where in your Ruby code the process is stuck.
You can check out some more tips here:
http://isotope11.com/blog/getting-a-ruby-backtrace-from-gnu-debugger
This is not a clean solution but at least the following resolved the problem for us: we migrated to the 'thin' webserver and removed 'devise'.

Rails server running in command prompt causing conhost.exe to crash

I have a Rails application that requires a bunch of environment stuff to get set up, and right now the easiest way for me to do it is to run a batch file to configure the environment and then launch the server from the command prompt. (Perhaps one day I will bite the bullet and transcribe all of the various environment variables into the project config, but I'd rather not...)
But when I do this, I occasionally manage to crash conhost.exe! It does not seem like I should be able to do this. Stranger still, it seems to happen most often if I access certain records in the application. I can't imagine it could crash if there were too much console output???
I am also having mscvrt-ruby.dll crashes, although I may have resolved those by doing some gem finagling. The conhost issue may or may not be related, I'm not sure. But if I launch the server from within RadRails, I don't seem to get these issues (the app doesn't completely work because of the missing environment stuff, but it seems much more stable).
Technicals: Windows 7, Rails 2.3.5, Ruby 1.93, Mongrel 1.2.0pre, uh, not sure what else...
Thoughts?

Stack Level Too Deep in Production Rails App - How to Get Details?

I am getting up and running with Spree in production on a 256MB Slicehost slice with MySQL, Mongrel, and Nginx. I am getting this error every time I try to access any URL in the app:
SystemStackError (stack level too deep):
compass (0.8.17) lib/compass/app_integration/rails/action_controller.rb:7:in `process'
vendor/plugins/haml/rails/./lib/sass/plugin/rack.rb:44:in `call'
(Some more test url requests are in this pastie)
What are the advanced (but free and open source) debugging strategies/tools I should use while in production mode so I can do better at solving this problem?
It's slightly different each time depending on the controller. I have tried increasing my stack size, but that doesn't help because there's probably just some loop I can't find.
The question is, how do I get a more detailed report of the exact output while in production?
I am using Deprec and Capistrano to execute all server side commands. I am running a mongrel cluster of 3. The log files I see are:
current/log$ ls
development.log
testsite.com-error.log
mongrel.8000.log
mongrel.8001.log
mongrel.8002.log
mongrel.log
production.log
testsite.com-access.log
I'm just looking for some advanced debugging strategies/tools while in production mode so I can do better at solving this problem. Maybe some cap tasks for streaming/debugging (or conditionally break-pointing!) the production app (really, a staging app) locally (do people do that?), or something that spits out every single thing that executes in code?
Thanks
I'd check all of your gems and plugins and any other dependencies your application might have: I'd guess that you're missing something (or have the wrong version of something) and it's failing badly enough that it can't even spit out a can't find require message.
check your action controller. On line 7 is most likely where the loop occurs.
Seems you have initiated some endless recursion on line 7 of your controller. Check if you are calling the same method inside the method.

Resources