Stack level too deep in activesupport callbacks

I am getting the SystemStackError in a Rails 3 app.

All the information I have is useless one line of a stacktrace (taken from the log):

SystemStackError (stack level too deep):
  activesupport (3.2.3) lib/active_support/callbacks.rb:409

So the question is how do I see the full stack trace?

NOTE: I don't care about why this happens, all I want is to see is where it happens.

Using: Rails 3.2.3, Unicorn.

Thanks.

Answers


That's pretty complex code in lib/active_support/callbacks.rb, but it looks like it is applying various callbacks: :before, :after, :around, to be precise.

You might try placing an old fashioned "puts before #{name}" before line 426 and seeing what you get.

Equally, could be that the entire stack trace is inside the rails stack, and it is being filtered out by the default backtrace_filter. Setting that backtrace_filter off might let you see the stack and get a debugging clue. See config/initializers/backtrace_silencers.rb and uncomment:

Rails.backtrace_cleaner.remove_silencers!


If you update an active record in it's before_save or after_save, it will keep on looping.... Also, if you have validates_associated on both ends of an association.

Here is an example of how a before_save callback can create a loop:

class Foo < ActiveRecord::Base
  def before_save
    self.update_attribute(:bar, 'badidea')
  end
end

For those that are able to upgrade to Ruby 2.2, you should get a much more descriptive stack trace as a result of work done by Nobu on MRI (https://bugs.ruby-lang.org/issues/6216). Switching to JRuby would also give a much deeper stack.


This is a shot in the dart but I hit something like this once when I had circular references in my validates_associated's


I had a similar issue. Controller Actions that were skipping before/after filters would eventually error out with the error

SystemStackError (stack level too deep):
  activesupport (3.2.13) lib/active_support/callbacks.rb:409

Best I can figure is that the way Rails adds/removes methods to the callback stack would create an error under heavy stress.

These are API calls, so I moved them to a separate controller that inherited from ActionController::Base, removing the need to skip filters. This solved my issue. ApplicationController::Metal may be a better choice depending on which features you need.

I know the asker was not concerned with why, but I figure other Rails Developers might run across the same issue, and none of the logging suggestions above returned a valid stack trace for me.


My answer doesn't answer the question directly but may help someone with the same problem. My suggestion is to develop and test in small pieces so we can undo the last changes and discover what broke ous code. Best if done with continuous integration and continuous delivery.

In my case the problem was pretty stupid. The problem was that I cloned my repository in a subdirectory instead of substituting it...


Need Your Help

Help Troubleshooting 1st Greasemoney Script

jquery greasemonkey

I'm trying to do my first greasemoney script. I'm fairly new to jquery and javascript, so be easy on me.

Animating with parameters in Javascript using a timer

javascript animation dojo timer

I'm trying to animate a dot from one point to another on a map. Right now I have the following code:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.