Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception pages in development mode take upwards of 15-30 seconds to render, why is that?

I am using Rails 3 beta 4 and for some reason I have each exception taking 15-30 seconds to show. Here is my trace:

Started GET "/something/something/approvals/new" for 127.0.0.1 at Thu Jun 24 21:17:12 -0400 2010
  SQL (1.8ms)  describe `approvals_users`
  SQL (24.6ms)  describe `clients_users`
  SQL (1.4ms)  describe `agencies_users`
  SQL (1.2ms)  describe `clients_users`
  SQL (1.2ms)  describe `approvals_users`
  SQL (1.7ms)  describe `permissions_users`
  Processing by ApprovalsController#new as HTML
  Parameters: {"project_id"=>"tricked", "client_id"=>"deez-nutz"}
  SQL (1.4ms)  describe `agencies_users`
  Agency Load (0.4ms)  SELECT `agencies`.* FROM `agencies` WHERE (`agencies`.`subdomain` = 'subdomain') LIMIT 1
  Plan Load (0.3ms)  SELECT `plans`.* FROM `plans` WHERE (`plans`.`id` = 3) LIMIT 1
  User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
Completed   in 93ms

NoMethodError (undefined method `humanize' for nil:NilClass):
  app/models/approval.rb:38:in `state'
  app/models/approval.rb:38:in `state'
  app/controllers/approvals_controller.rb:10:in `new'
  app/controllers/approvals_controller.rb:10:in `new'

Rendered /Users/garrett/.bundle/ruby/1.8/bundler/gems/rails-07b08721a226ff01f983e61d99ab4da96e296c97-6682cce0386811ffe3e6d31fc025ede0936d86c3/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms)
  SQL (2.5ms)  SHOW TABLES
  SQL (0.9ms)  SHOW TABLES
  SQL (0.9ms)  SHOW TABLES
  SQL (0.9ms)  SHOW TABLES
  SQL (0.9ms)  SHOW TABLES
  SQL (0.9ms)  SHOW TABLES
  SQL (0.9ms)  SHOW TABLES
  SQL (0.9ms)  SHOW TABLES
Rendered /Users/garrett/.bundle/ruby/1.8/bundler/gems/rails-07b08721a226ff01f983e61d99ab4da96e296c97-6682cce0386811ffe3e6d31fc025ede0936d86c3/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (21433.7ms)
Rendered /Users/garrett/.bundle/ruby/1.8/bundler/gems/rails-07b08721a226ff01f983e61d99ab4da96e296c97-6682cce0386811ffe3e6d31fc025ede0936d86c3/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (21630.2ms)

If it helps at all, here is my Gemfile:

source 'http://gemcutter.org'

# Core
# gem 'rails', '3.0.0.beta4'
gem 'rails', :git => 'http://github.com/rails/rails.git'
gem 'sinatra'
gem 'mysql'
gem 'bundler'
gem 'memcache-client'
gem 'system_timer'
gem 'mime-types', :require => 'mime/types'
gem 'json'
gem 'haml', '~> 3.0.12'
gem 'state_machine'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'juicer'
gem 'hoptoad_notifier'
gem 'braintree'
gem 'panda'

# Templating
gem 'liquid', '2.0.0'

# Users
gem 'warden'
gem 'ruby-openid', :require => 'openid'
gem 'canable'
gem 'devise'

# Paperclip
gem 'aws-s3', :require => 'aws/s3'
gem 'paperclip', :git => 'git://github.com/dewski/paperclip.git', :branch => 'rails3'
gem 'delayed_job', :git => 'git://github.com/dewski/delayed_job.git'

group :test do
  gem 'webrat'
  gem 'hpricot'
  gem 'mocha', :require => false
end

If I create a new Rails app, error pages show instantly. In the Rails source code, the method that has SHOW TABLES is structure_dump in schema_statements.rb. I searched my bundler directory for any sort of call to this method and it's not showing anything. What gives and how could this be caused to were SHOW TABLES is called over and over again and possibly making it so every method makes it pain to debug?

like image 957
Garrett Avatar asked Jun 25 '10 01:06

Garrett


People also ask

How do you test error boundaries in development?

With the new feature in React, developers can test the Error Boundaries by a toggle error button, added to the DevTools. When we click on the toggle error button on the component labeled 'Inner Component', Error boundary is triggered.

How do you handle error boundaries in functional components?

In order to use Error Boundary in Functional Component, I use react-error-boundary. When we run this application, we will get a nice error display form the content of ErrorHandler component. React error boundary catches any error from the components below them in the tree.

How many error boundaries We can create and use?

Now that Error Boundaries are available since React version 16, it's generally advisable to use at least one Error Boundary at the root of your app (e.g., the App. js file).

How do you handle errors in React app?

Error handling with Error Boundaries — For class components. Error boundaries are the most straightforward and effective way to handle errors that occur within your React components. You can create an error boundary component by including the life cycle method componentDidCatch(error, info) if you use class component.


1 Answers

We've run into this problem at our company, and while we wait for an official Rails point release, have put together a hack. The key issue, as mentioned in the Lighthouse ticket linked in the other answer, seems to be that for some apps, request.env contains some objects whose #inspect output is HUGE (like, megabytes of text), and this output all gets put into the error page.

So here it is:

# development.rb

config.after_initialize do    
  module SmallInspect
    def inspect
      "<#{self.class.name} - tooooo long>"
    end
  end
  [ActionDispatch::RemoteIp::RemoteIpGetter, OmniAuth::Strategies::Facebook, ActionController::Base, Warden::Proxy].each do |klazz|
    klazz.send(:include, SmallInspect)
  end
end

The classes listed are the main culprits for us; yours will vary depending on your app.

like image 191
lawrence Avatar answered Nov 14 '22 21:11

lawrence