1
votes

I have a problem on my ruby on rails application. It uses too much memory whenever it encounters an undefined method. It freezes the server until I kill the process. Error log points to the undefined method that goes to something like this:

ActionView::Template::Error (undefined method `testos' for #<#:0x007fb3d88de8c8>):

Is there any way or configuration to fix this? I am using ruby 1.9.3 on rails 3.2.2.

Here is the stack trace

Completed 500 Internal Server Error in 53960ms

ActionView::Template::Error (undefined method testos' for #<#<Class:0x007fb3d43d0420>:0x007fb3d479c8d8>): 77: @rules["data"].each do |rule| 78: json_rule =ActiveSupport::JSON.decode(rule["json_rule"])
79: %>
80: <%=testos(1)%>
81: <div class="dvGridRow" style="width:100%;padding-bottom:10px;">
82: <div class="dvGridData" style="vertical-align:top;width:190px;margin-left:5px;">
83: <%= json_rule["rule_name"]%>
app/views/rules/index.html.erb:80:in
block in _app_views_rules_index_html_erb_4146358986539966513_70205169705180'
app/views/rules/index.html.erb:77:in each'
app/views/rules/index.html.erb:77:in
_app_views_rules_index_html_erb
_4146358986539966513_70205169705180'

Rendered /Users/jay/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (6.4ms) cache: [GET /manage/rules] miss Rendered /Users/jay/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.8ms) Rendered /Users/jay/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.2/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (18.5ms)

note: I intentionally called an unidentified method, because I am trying to figure out where does my code freezes the machine, and that error causes it.

Thanks

1
It would greatly help if you add some context, like the backtrace, a part of the template, and related code.rewritten
@saverio: I hope the stack trace helps.jaxx05
I don't get it. Is the error causing your memory usage to grow, or any normal run? Normal causes of memory leaks are loops and similar thing. One code smell is the JSON.decode call, it may instantiate many objects.rewritten
Yes, memory usage grows greatly whenever there is undefined method that is call. If that code is remove, the program runs smoothly. So I am pretty sure that the culprit for my massive memory utilisation is whenever there is an undefined method.jaxx05
I am pretty sure that's not the culprit. Most probably the appearance of an undefinde method call triggers some leak. Try to raise a different exception (like dividing by 0) instead, and see if the memory still grows.rewritten

1 Answers

0
votes

A Problem (and a Solution)

Let’s say your working with a Ruby object. And let’s also say that you aren’t entirely familiar with this object. And let’s also say that you call a method that doesn’t exist on the object.

o = Object.new  
o.some_method  

NoMethodError: undefined method `some_method' for #

This is less than desirable, so Ruby has an awesome way of allowing us to rescue ourselves from this. Check this out:

class OurClass  
  def method_missing (method_name)  
    puts "there's no method called '#{method_name}'"  
  end  
end  
o = OurClass.new  
o.some_method 

=> there's no method called 'some_method'

We can create a method called method_missing in our class. If the object we’re calling the method on doesn’t have the method (and doesn’t inherit the method from another class or module), Ruby will give us one more chance to do something useful: if the class has a method_missing method, we’ll hand the information about the method cal to method_missing and let it sort the mess out. Well, that’s great; we’re no longer getting an error message.

reference from this link http://net.tutsplus.com/tutorials/ruby/ruby-for-newbies-missing-methods/