Skip to content

Instantly share code, notes, and snippets.

@sbull
Created April 9, 2015 06:53
Show Gist options
  • Save sbull/114f93a374136ace74f1 to your computer and use it in GitHub Desktop.
Save sbull/114f93a374136ace74f1 to your computer and use it in GitHub Desktop.
debugging https://github.com/rails/rails/issues/19084, reproduction against rails master
$ bundle exec rails runner route_helpers_debug.rb 20 && spring stop
Threads: 20, Iterations per thread: 20
Running Mounted Engine dummy_path...
6/-/16/-/19/-/15/-/14/-/7/-/13/-/12/-/3/-/8/-/9/-/2/-/5/-/1/-/0/-/10/-/18/-/11/-/4/-/17/-/12/-/7/-/3/-/2/-/9/-/1/-/0/-/14/-/15/-/10/-/8/-/11/-/16/-/4/-/11/-/13/-
/18/-/6/-/17/-/12/-/6/-/7/-/3/-/6/-/9/-/1/-/6/-/15/-/10/-/5/-/8/-/16/-/11/-/19/-/13/-/17/-/2/-/18/-/7/-/3/-/0/-/14/-/9/-/6/-/1/-/15/-/10/-/4/-/5/-/8/-/4/-/19/-/1
3/-/17/-/2/-/18/-/12/-/2/-/0/-/3/-/14/-/9/-/6/-/15/-/14/-/16/-/11/-/10/-/5/-/8/-/10/-/13/-/19/-/7/-/17/-/12/-/13/-/0/-/2/-/13/-/3/-/6/-/15/-/16/-/13/-/11/-/4/-/1
3/-/8/-/19/-/18/-/7/-/17/-/18/-/0/-/2/-/14/-/0/-/3/-/6/-/15/-/11/-/16/-/4/-/10/-/13/-/8/-/1/-/19/-/8/-/17/-/12/-/8/-/18/-/2/-/14/-/0/-/5/-/6/-/3/-/15/-/16/-/11/-
/4/-/10/-/7/-/13/-/17/-/19/-/12/-/8/-/19/-/2/-/8/-/5/-/0/-/15/-/6/-/11/-/16/-/10/-/4/-/16/-/9/-/7/-/13/-/18/-/17/-/14/-/18/-/19/-/2/-/8/-/0/-/5/-/0/-/6/-/1/-/10/
-/4/-/1/-/16/-/7/-/12/-/17/-/14/-/18/-/19/-/2/-/3/-/15/-/5/-/8/-/0/-/11/-/9/-/6/-/16/-/1/-/7/-/4/-/10/-/12/-/1/-/7/-/14/-/18/-/19/-/3/-/2/-/15/-/5/-/2/-/0/-/17/-
/9/-/13/-/10/-/4/-/16/-/1/-/12/-/7/-/14/-/12/-/19/-/8/-/11/-/3/-/0/-/17/-/2/-/6/-/5/-/15/-/13/-/9/-/3/-/18/-/1/-/16/-/7/-/18/-/19/-/8/-/11/-/17/-/2/-/10/-/11/-/4
/-/13/-/5/-/9/-/3/-/14/-/15/-/1/-/16/-/7/-/12/-/18/-/19/-/8/-/18/-/17/-/10/-/2/-/10/-/11/-/13/-/5/-/9/-/14/-/13/-/15/-/1/-/16/-/13/-/1/-/19/-/8/-/18/-/4/-/17/-/1
8/-/10/-/11/-/5/-/7/-/12/-/14/-/15/-/13/-/1/-/13/-/2/-/8/-/4/-/2/-/3/-/18/-/2/-/11/-/5/-/7/-/12/-/16/-/19/-/7/-/16/-/1/-/10/-/9/-/3/-/4/-/8/-/18/-/2/-/8/-/14/-/5
/-/15/-/17/-/12/-/16/-/19/-/7/-/10/-/1/-/9/-/7/-/11/-/18/-/14/-/5/-/12/-/17/-/14/-/16/-/19/-/4/-/16/-/9/-/15/-/7/-/9/-/3/-/12/-/5/-/14/-/3/-/5/-/4/-/12/-/11/-/15
/-/17/-/12/-/9/-/1/-/19/-/4/-/3/-/14/-/5/-/11/-/15/-/10/-/17/-/12/-/15/-/19/-/4/-/14/-/9/-/3/-/5/-/11/-/1/-/4/-/3/-/9/-/17/-/10/-/1/-/
Finished thread 1.
Finished thread 2.
Finished thread 3.
Finished thread 4.
Finished thread 5.
9/-/
Finished thread 7.
Finished thread 8.
9/-/
Finished thread 9.
Finished thread 10.
Finished thread 11.
Finished thread 12.
Finished thread 13.
Finished thread 14.
Finished thread 15.
Finished thread 16.
Finished thread 17.
Finished thread 18.
Finished thread 19.
-------
ERRORS: 2
Exception in thread 0, iteration 14: undefined method `url_options' for #<Module:0x007f42aa9785a8>
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:246:in `call'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:195:in `call'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:300:in `block (2 levels) in define_url_helper'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/mapper.rb:621:in `block (2 levels) in define_generate_prefix'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:742:in `url_for'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:254:in `call'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:195:in `call'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:300:in `block (2 levels) in define_url_helper'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/routes_proxy.rb:32:in `dummy_path'
route_helpers_debug.rb:48:in `engine_test'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/home/steven/pushhealth/rails-master/actionpack/lib/abstract_controller/base.rb:189:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/rendering.rb:21:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:117:in `call'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:117:in `call'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:558:in `block (2 levels) in compile'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:501:in `call'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:501:in `call'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:90:in `run_callbacks'
/home/steven/pushhealth/rails-master/actionpack/lib/abstract_controller/callbacks.rb:19:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/rescue.rb:29:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/notifications.rb:164:in `block in instrument'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/notifications.rb:164:in `instrument'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
/home/steven/pushhealth/rails-master/activerecord/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/abstract_controller/base.rb:128:in `process'
/home/steven/pushhealth/rails-master/actionview/lib/action_view/rendering.rb:30:in `process'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal.rb:194:in `dispatch'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal.rb:241:in `block in action'
route_helpers_debug.rb:57:in `call'
route_helpers_debug.rb:57:in `block in <top (required)>'
route_helpers_debug.rb:15:in `call'
route_helpers_debug.rb:15:in `block (3 levels) in run_threads'
route_helpers_debug.rb:13:in `times'
route_helpers_debug.rb:13:in `block (2 levels) in run_threads'
Exception in thread 6, iteration 14: undefined method `url_options' for #<Module:0x007f42adf266c8>
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:246:in `call'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:195:in `call'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:300:in `block (2 levels) in define_url_helper'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/mapper.rb:621:in `block (2 levels) in define_generate_prefix'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:742:in `url_for'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:254:in `call'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:195:in `call'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/route_set.rb:300:in `block (2 levels) in define_url_helper'
/home/steven/pushhealth/rails-master/actionpack/lib/action_dispatch/routing/routes_proxy.rb:32:in `dummy_path'
route_helpers_debug.rb:48:in `engine_test'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/home/steven/pushhealth/rails-master/actionpack/lib/abstract_controller/base.rb:189:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/rendering.rb:21:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:117:in `call'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:117:in `call'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:558:in `block (2 levels) in compile'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:501:in `call'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:501:in `call'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/callbacks.rb:90:in `run_callbacks'
/home/steven/pushhealth/rails-master/actionpack/lib/abstract_controller/callbacks.rb:19:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/rescue.rb:29:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/notifications.rb:164:in `block in instrument'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/steven/pushhealth/rails-master/activesupport/lib/active_support/notifications.rb:164:in `instrument'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
/home/steven/pushhealth/rails-master/activerecord/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home/steven/pushhealth/rails-master/actionpack/lib/abstract_controller/base.rb:128:in `process'
/home/steven/pushhealth/rails-master/actionview/lib/action_view/rendering.rb:30:in `process'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal.rb:194:in `dispatch'
/home/steven/pushhealth/rails-master/actionpack/lib/action_controller/metal.rb:241:in `block in action'
route_helpers_debug.rb:57:in `call'
route_helpers_debug.rb:57:in `block in <top (required)>'
route_helpers_debug.rb:15:in `call'
route_helpers_debug.rb:15:in `block (3 levels) in run_threads'
route_helpers_debug.rb:13:in `times'
route_helpers_debug.rb:13:in `block (2 levels) in run_threads'
-------
ERRORS: 2
Spring stopped.
$ cat route_helpers_debug.rb
# via "rails runner"
NUM_THREADS = (ARGV[0] || 10).to_i
NUM_ITERATIONS = (ARGV[1] || NUM_THREADS).to_i
puts "Threads: #{NUM_THREADS}, Iterations per thread: #{NUM_ITERATIONS}"
def run_threads(&block)
threads = []
NUM_THREADS.times do |thread_num|
threads << Thread.new(thread_num) do |num|
Thread.current.thread_variable_set('num', num)
NUM_ITERATIONS.times do |i|
Thread.current.thread_variable_set('iter', i)
print num.to_s + block.call.to_s
end
end
end
errors = []
threads.each do |thr|
begin
thr.join
print "\nFinished thread #{thr.thread_variable_get('num')}.\n"
rescue => e
errors << "\nException in thread #{thr.thread_variable_get('num')}, iteration #{thr.thread_variable_get('iter')}: #{e.message}\n"+e.backtrace.map{|bt| "\t#{bt}\n" }.join
end
end
puts "\n-------\nERRORS: #{errors.length}"
puts errors
puts "\n-------\nERRORS: #{errors.length}"
end
class TestEngine < Rails::Engine; end
TestEngine.routes.draw do
get '/' => 'dummy#index', as: :dummy
end
Rails.application.routes.draw do
root to: 'dummy#index'
mount TestEngine, at: '-', as: 'test_routes'
end
class TestController < ActionController::Base
def engine_test
render plain: test_routes.dummy_path
end
end
Rails.logger.level = 2
puts "Running Mounted Engine dummy_path..."
run_threads do
env = { 'REQUEST_METHOD' => 'GET', 'rack.input' => StringIO.new }
status, headers, rack_body = TestController.action('engine_test').call(env)
rack_body.body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment