Connection timeout for SOCKSProxy Calls in resque Rails production mode - ruby-on-rails-3

i have simple background job that runs using resque-pool which makes certain socksproxy call. This works fine when i start the resque-pool in Rails development mode as soon as i change to production mode i hit connection timeout with background job
The same code works when executed in
Rails Console in Production mode
Standalone ruby script invoked from command line
calls are something like:
req = Net::HTTP::Get.new(uri.request_uri)
response = Net::HTTP.SOCKSProxy(#socks_server, #socks_port).start(uri.host, uri.port) do |http|
http.request(req)
end
Investigation:
when this call happens in net/http.rb
TCPSocket.open(conn_address, conn_port, #local_host, #local_port)
i found that in production mode worker child process instead of loading
TCPSocket class from socksify-1.7.0/lib/socksify.rb it is still loading from ruby provided resolv-replace.rb. Not sure why though.
Error i see:
Connection timed out - connect(2) for "" port 6455:
/usr/lib/ruby/gems/2.1.0/gems/socksify-1.7.0/lib/socksify.rb:178:in
initialize'
/usr/lib/ruby/gems/2.1.0/gems/socksify-1.7.0/lib/socksify.rb:178:in
initialize' /usr/lib/ruby/2.1.0/resolv-replace.rb:23:in initialize'
/usr/lib/ruby/2.1.0/net/http.rb:879:inopen'
/usr/lib/ruby/2.1.0/net/http.rb:879:in block in connect'
/usr/lib/ruby/2.1.0/timeout.rb:76:intimeout'
/usr/lib/ruby/2.1.0/net/http.rb:878:in connect'
/usr/lib/ruby/2.1.0/net/http.rb:863:indo_start'
/usr/lib/ruby/2.1.0/net/http.rb:852:in start'
/usr/lib/ruby/2.1.0/net/http.rb:583:instart'
/usr/lib/ruby/gems/2.1.0/gems/retries-0.0.5/lib/retries.rb:46:in
call'
/usr/lib/ruby/gems/2.1.0/gems/retries-0.0.5/lib/retries.rb:46:in
with_retries'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:177:in
block (3 levels) in perform'
/usr/lib/ruby/gems/2.1.0/gems/newrelic_rpm-3.16.2.321/lib/new_relic/agent/instrumentation/resque.rb:41:in
block in around_perform_with_monitoring'
/usr/lib/ruby/gems/2.1.0/gems/newrelic_rpm-3.16.2.321/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:363:in
`perform_action_with_newrelic_trace'
/usr/lib/ruby/gems/2.1.0/gems/newrelic_rpm-3.16.2.321/lib/new_relic/agent/instrumentation/resque.rb:33:in
around_perform_with_monitoring'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:176:in
block (2 levels) in perform'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:172:in
call'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:172:in
block (3 levels) in perform' ../app/jobs/resque_hooks.rb:15:in
around_perform_job_duration'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:172:in
block (2 levels) in perform'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:184:in
call'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/job.rb:184:in
perform'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/worker.rb:290:in
perform'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/worker.rb:229:in
block in work'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/worker.rb:206:in
loop'
/usr/lib/ruby/gems/2.1.0/gems/resque-1.26.0/lib/resque/worker.rb:206:in
work'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:396:in
block in spawn_worker!'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:389:in
fork'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:389:in
spawn_worker!'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:367:in
block in spawn_missing_workers_for'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:366:in
times'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:366:in
spawn_missing_workers_for'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:352:in
block in maintain_worker_count'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:350:in
each'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:350:in
maintain_worker_count'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:263:in
start'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool.rb:89:in
run'
/usr/lib/ruby/gems/2.1.0/gems/resque-pool-0.6.0/lib/resque/pool/tasks.rb:17:in
block (2 levels) in '
/usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:248:in
call'
/usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:248:in
block in execute'
/usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:243:in
each'
/usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:243:in
execute'
/usr/lib/ruby/gems/2.1.0/gems/airbrake-5.5.0/lib/airbrake/rake/task_ext.rb:19:in
execute'
/usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:187:in
block in invoke_with_call_chain'
/usr/lib/ruby/2.1.0/monitor.rb:211:in mon_synchronize'
/usr/lib/ruby/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:180:in
invoke_with_call_chain

After more investigation it turns due to newrelic gem enabled in production mode. newrelic requires resolv-replace this didnt go well with socksify gem and resque background job. As i did not need new relic anymore, simply by disabling it i was able to overcome this issue.

Related

To submit an issue include the stack trace

i use the command -> shopify theme serve then appears this error:
X An unexpected error occured.
To submit an issue include the stack trace.
? Send an anonymized error report to Shopify? (You chose: No, don't send)
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/file.rb:137:in []=': no implicit conversion of String into Integer (TypeError) from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/file.rb:137:in visit_value'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/file.rb:130:in block in visit_hash' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/file.rb:129:in each'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/file.rb:129:in visit_hash' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/file.rb:124:in visit_document'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/file.rb:113:in normalize_json' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/file.rb:81:in checksum'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/syncer/checksums.rb:20:in file_has_changed?' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/syncer/json_update_handler.rb:19:in block in enqueue_json_updates'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/syncer/json_update_handler.rb:19:in select' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/syncer/json_update_handler.rb:19:in enqueue_json_updates'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/syncer.rb:173:in upload_theme!' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/project_types/theme/ui/sync_progress_bar.rb:11:in public_send'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/project_types/theme/ui/sync_progress_bar.rb:11:in block in progress' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-ui/lib/cli/ui/progress.rb:34:in progress'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/project_types/theme/ui/sync_progress_bar.rb:10:in progress' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/project_types/theme/commands/serve.rb:31:in block in call'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/dev_server.rb:56:in block in start' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-ui/lib/cli/ui/frame.rb:103:in open'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/theme/dev_server.rb:52:in start' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/project_types/theme/commands/serve.rb:30:in call'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/command/sub_command.rb:16:in call' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/command.rb:27:in call'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/core/executor.rb:17:in block (2 levels) in call' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-kit/lib/cli/kit/executor.rb:37:in block (2 levels) in with_logging'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb:169:in with_id' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-kit/lib/cli/kit/executor.rb:36:in block in with_logging'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-ui/lib/cli/ui.rb:176:in log_output_to' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-kit/lib/cli/kit/executor.rb:35:in with_logging'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/core/executor.rb:16:in block in call' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-kit/lib/cli/kit/executor.rb:45:in block (2 levels) in with_traps'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-kit/lib/cli/kit/executor.rb:51:in twrap' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-kit/lib/cli/kit/executor.rb:44:in block in with_traps'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-kit/lib/cli/kit/executor.rb:51:in twrap' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-kit/lib/cli/kit/executor.rb:43:in with_traps'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/core/executor.rb:15:in call' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/core/entry_point.rb:24:in block in call'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/core/monorail.rb:26:in log' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/lib/shopify_cli/core/entry_point.rb:23:in call'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/bin/shopify:50:in block (2 levels) in <top (required)>' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb:75:in handle_abort'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb:21:in call' from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/bin/shopify:49:in block in <top (required)>'
from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/shopify-cli-2.18.1/bin/shopify:59:in <top (required)>' from C:/Ruby31-x64/bin/shopify:32:in load'
from C:/Ruby31-x64/bin/shopify:32:in `'
Hey before running the command make sure you check these:
You are in the theme root folder.
You are logged in using shopify login and you have the right to edit themes.
You are connected to your internet.
If all of these are checked you might wanna reduce the Shopify version to a lower version like 2.5.0, or submit a bug in Shopify CLI in Github here: https://github.com/Shopify/shopify-cli/issues

Rails test fails requests did not finish in 60 seconds

After upgrading rails from 4.2 to 5.2 my test gets stuck on a request while it is working in development server I'm getting following failure on running test suit.
Failures:
1) cold end overview shows cold end stats
Failure/Error: example.run
RuntimeError:
Requests did not finish in 60 seconds
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/capybara-2.18.0/lib/capybara/server.rb:94:in `rescue in wait_for_pending_requests'
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/capybara-2.18.0/lib/capybara/server.rb:91:in `wait_for_pending_requests'
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/capybara-2.18.0/lib/capybara/session.rb:130:in `reset!'
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/capybara-2.18.0/lib/capybara.rb:314:in `block in reset_sessions!'
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/capybara-2.18.0/lib/capybara.rb:314:in `reverse_each'
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/capybara-2.18.0/lib/capybara.rb:314:in `reset_sessions!'
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/capybara-2.18.0/lib/capybara/rspec.rb:22:in `block (2 levels) in <top (required)>'
# ./spec/spec_helper.rb:43:in `block (3 levels) in <top (required)>'
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/database_cleaner-1.6.2/lib/database_cleaner/generic/base.rb:16:in `cleaning'
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/database_cleaner-1.6.2/lib/database_cleaner/base.rb:98:in `cleaning'
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/database_cleaner-1.6.2/lib/database_cleaner/configuration.rb:86:in `block (2 levels) in cleaning'
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/database_cleaner-1.6.2/lib/database_cleaner/configuration.rb:87:in `cleaning'
# ./spec/spec_helper.rb:37:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# Timeout::Error:
# execution expired
# /home/asnad/.rvm/gems/ruby-2.5.0/gems/capybara-2.18.0/lib/capybara/server.rb:92:in `sleep'
Top 1 slowest examples (62.59 seconds, 97.0% of total time):
cold end overview shows cold end stats
62.59 seconds ./spec/features/cold_end_overview_spec.rb:13
Finished in 1 minute 4.51 seconds (files took 4.15 seconds to load)
1 example, 1 failure
my spec_helper.rb has configurations
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
config.around(:each) do |example|
DatabaseCleaner[:active_record].clean_with(:truncation)
DatabaseCleaner.cleaning do
if example.metadata.key?(:js) || example.metadata[:type] == :feature
# VCR.configure { |c| c.ignore_localhost = true }
WebMock.allow_net_connect!
VCR.turn_off!
VCR.eject_cassette
example.run
else
# WebMock.disable_net_connect!
VCR.turn_on!
cassette_name = example.metadata[:full_description]
.split(/\s+/, 2)
.join('/')
.underscore.gsub(/[^\w\/]+/, '_')
# VCR.configure { |c| c.ignore_localhost = false }
VCR.use_cassette(cassette_name) { example.run }
VCR.turn_off!
WebMock.allow_net_connect!
end
end
end
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.filter_run :focus
config.run_all_when_everything_filtered = true
config.example_status_persistence_file_path = "spec/examples.txt"
if config.files_to_run.one?
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
end
# Selenium::WebDriver.logger.level = :debug
# Selenium::WebDriver.logger.output = 'selenium.log'
Capybara.register_driver :selenium_chrome_headless do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(chromeOptions: { args: %w[headless no-sandbox disable-dev-shm-usage disable-gpu window-size=1200,1500] }, loggingPrefs: { browser: 'ALL' })
Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities)
end
Chromedriver.set_version '2.39'
Capybara.javascript_driver = :selenium_chrome_headless
Capybara::Screenshot.prune_strategy = :keep_last_run
in my spec the line sign_in current_user takes too much time actually it redirects to a page and do not get response even long time while it is working on development environment.
what can be the reason if you need anything else please comment.
I've just arrived here myself after upgrading from 4.2 to 5.1 and now 5.2, and I'm seeing the same thing in my testing, when I have frozen a test in mid-request with binding.pry, I get the message Requests did not finish in 60 seconds. What a great story, skip to the end for tl;dr (I may have figured it out.)
Now I have upgraded all of the gems, incrementally so I can preserve the capacity to bisect and observe the source of interesting changes like this one. I only noticed this new 60 second timeout after changing over from chromedriver-helper which reported it had been deprecated to the new webdrivers gem that's taking over, but that seems to be not related as I searched webdrivers for any timeout or 60 second value, and only found references to an unrelated Pull Request #60 (fixes Issue #59).
I checked my gem source directory for this message, Requests did not finish in 60 seconds, and found it was not in fact an older version of Capybara, but that it has been raised from versions dating back to at least 3.9.0, and in the most current version 3.24.0 in lib/capybara/server.rb.
The object used there is a Timer which you can find an interface to it here, in the helper:
https://github.com/teamcapybara/capybara/blob/320ee96bb8f63ac9055f7522961a1e1cf8078a8a/lib/capybara/helpers.rb#L79
This particular message is raised out of the method wait_for_pending_requests which passes a hard 60 into the :expire_in named parameter, then after sends any errors that were encountered in the server thread. This means the time is not configurable, probably 60 seconds is a reasonable length of time to wait for a web request in progress to complete, although it's a bit inconvenient for my test.
That method is only called in one place, reset!, which you can find defined here in capybara/session.rb: https://github.com/teamcapybara/capybara/blob/320ee96bb8f63ac9055f7522961a1e1cf8078a8a/lib/capybara/session.rb#L126
The reset! method is an interesting one that comes with some documentation about how it's used. #server&.wait_for_pending_requests looks like it might call wait_for_pending_requests if it has an active server thread in a request, and then raise_server_error! which similarly acts only if #server&.error is truthy.
Now we find that reset! comes with two aliases, this message reset! is received whenever Capybara calls cleanup! or reset_session!. At this point we can probably understand what happened, but it's still a little bit mysterious when I've been using chromedriver-helper and selenium testing for several years, but never recall seeing this 60 second timeout before. I'm hesitant to point the finger at webdriver, but I don't have any other answers for why this timeout is new. I haven't done really anything that could account for it but upgrade to this gem, and any other gems, plus clearing out deprecation warnings.
It seems possible that in Rails 5.1+, capybara calls reset! a lot more, maybe more than in between test examples. Especially when you read that documentation of the method and think about what Single-Page focus there has been now, and consider all of the things that reset! documentation tells you it doesn't reset, clear browser cache/HTML 5 local storage/IndexedDB/Web SQL database/etc — or maybe I'm imagining it, and this isn't new. But I'm imagining there are a lot of ways that it can call reset! and not land in this timeout code, that are likely to be driver-dependent.
Did you change to webdrivers gem by any chance when you did your Rails upgrade?
Edit: I reverted to chromedriver-helper just to be sure, and that wasn't it. What's actually happening is my test is failing in one thread, but the server has left a binding.pry session open. Capybara has moved onto the next test, and thus to get a fresh session it has called reset!, but 60 seconds later I am still in my pry session, and the server is still not ready to serve a root request. I have a feeling that the threading behavior of capybara has changed, in my memory a pry session opened during a server request would block the test from failing until it had returned. But that's apparently not what's happening anymore.
How did you arrive here? I have no idea unfortunately, but this is a fair description of what's happening when that message is received.

Undefined class/module in ruby on rails

I created map_job.rb in project lib folder. But why I am getting this error when delayed job.
error message
"last_error": "Job failed to load: undefined class/module MapJob. Handler: \"--- !ruby/struct:MapJob\nid: aa\n\"\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:87:in rescue in payload_object'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:85:inpayload_object'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:95:in block in invoke_job'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:incall'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:in block in initialize'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:incall'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:in execute'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:38:inrun_callbacks'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:92:in invoke_job'\n(eval):3:inblock in invoke_job_with_newrelic_transaction_trace'\n/app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.9.2.239/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:365:in perform_action_with_newrelic_trace'\n(eval):2:ininvoke_job_with_newrelic_transaction_trace'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:203:in block (2 levels) in run'\n/app/vendor/ruby-1.9.3/lib/ruby/1.9.1/timeout.rb:69:intimeout'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:203:in block in run'\n/app/vendor/ruby-1.9.3/lib/ruby/1.9.1/benchmark.rb:295:inrealtime'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:202:in run'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:259:inblock in reserve_and_run_one_job'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:in call'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:inblock in initialize'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:in call'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:inexecute'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:38:in run_callbacks'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:259:inreserve_and_run_one_job'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:187:in block in work_off'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:186:intimes'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:186:in work_off'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:151:inblock (4 levels) in start'\n/app/vendor/ruby-1.9.3/lib/ruby/1.9.1/benchmark.rb:295:in realtime'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:150:inblock (3 levels) in start'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:in call'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:inblock in initialize'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:in call'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:inexecute'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:38:in run_callbacks'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:149:inblock (2 levels) in start'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:148:in loop'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:148:inblock in start'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/plugins/clear_locks.rb:7:in call'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/plugins/clear_locks.rb:7:inblock (2 levels) in '\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:78:in call'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:78:inblock (2 levels) in add'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:in call'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:inblock in initialize'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:78:in call'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:78:inblock in add'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:in call'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:inexecute'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:38:in run_callbacks'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.rb:147:instart'\n/app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/tasks.rb:9:in block (2 levels) in <top (required)>'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/task.rb:240:incall'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/task.rb:240:in block in execute'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/task.rb:235:ineach'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/task.rb:235:in execute'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/task.rb:179:inblock in invoke_with_call_chain'\n/app/vendor/ruby-1.9.3/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/task.rb:172:ininvoke_with_call_chain'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/task.rb:165:in invoke'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:150:ininvoke_task'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:106:in block (2 levels) in top_level'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:106:ineach'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:106:in block in top_level'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:115:inrun_with_threads'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:100:in top_level'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:78:inblock in run'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:176:in standard_exception_handling'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/lib/rake/application.rb:75:inrun'\n/app/vendor/bundle/ruby/1.9.1/gems/rake-10.3.2/bin/rake:33:in <top (required)>'\n/app/vendor/bundle /ruby/1.9.1/bin/rake:23:inload'\n/app/vendor/bundle/ruby/1.9.1/bin/rake:23:in `'",
Please help me. Any help would be greatly appreciated!
You need to autoload map_job.rb
Do this in your application.rb file and restart your server.
require "#{Rails.root.to_s}/lib/map_job.rb"
Do you have a class/Module named MapJob in your map_job.rb file?. The Error complains that you have not defined a class/module with that name

ActiveRecord::StatementInvalid. PG Error

I am trying to find a project from Project model using Project.find(id) but it is giving me ActiveRecord::StatementInvalid error
Full trace-
PG::Error: ERROR: prepared statement "a1" already exists : SELECT COUNT(*) FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind in ('v','r') AND c.relname = $1 AND n.nspname = ANY (current_schemas(false))
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1180:in `prepare'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1180:in `prepare_statement'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1144:in `exec_cache'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord- 3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in `block in exec_query'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activesupport-3.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:662:in `exec_query'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:797:in `table_exists?'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/connection_adapters/schema_cache.rb:30:in `table_exists?'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:223:in `table_exists?'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/attribute_methods/primary_key.rb:75:in `get_primary_key'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/attribute_methods/primary_key.rb:60:in `reset_primary_key'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/attribute_methods/primary_key.rb:49:in `primary_key'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:230:in `block in columns'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `map'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:228:in `columns'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/model_schema.rb:237:in `columns_hash'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/relation/delegation.rb:7:in `columns_hash'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:330:in `find_one'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:311:in `find_with_ids'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/relation/finder_methods.rb:107:in `find'
/home/deploy/.rvm/gems/ruby-1.9.2-p290#submit_contactpl/gems/activerecord-3.2.2/lib/active_record/querying.rb:5:in `find'
/home/deploy/submit_contactpl/app/workers/php_worker.rb:5:in `perform'
Line 5 of php_worker is
project = Project.find(project_id)
What might be the issue? Could you shade some light on it. What might be the possible solution
all it needed was
task "resque:setup" => :environment do
#ENV['QUEUE'] = '*'
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
in your resque.rake file
It's a bug somewhere in your Ruby stack.
It's trying to prepare a statement called "a1" which is examining table/view definitions (presumably for your "project" table). It finds out a prepared statement with the same name already exists and spits out an error. The query it is trying to prepare is fine - it returns a count of how many tables have a given name.
Either it's not tracking its prepared statements properly or it thinks it's deleted one and hasn't really. I'd update rails & activerecord and check for bug reports.

Cucumber "--format progress" doesn't work

In my cucumber.yml I've tried to add this option (default: --drb --format progress), but it return an error :
Exception encountered: #<ArgumentError: wrong number of arguments (3 for 2)
Error creating formatter: progress>
When I take it in brackets default: --drb --"format progress" it doesn't helps:
invalid option: --format progress (OptionParser::InvalidOption)
So maybe there is no option, but it should be
And "format pretty" works correctly without any brackets.
I want see not all scenarios in console, but just which has an errors, perhaps there is another way to do this.
Full trace:
wrong number of arguments (3 for 2)
Error creating formatter: progress (ArgumentError)
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/activerecord-3.1.0/lib/active_record/base.rb:1543:in `initialize'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:168:in `new'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:168:in `block in formatters'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:163:in `map'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:163:in `formatters'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:68:in `build_tree_walker'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/runtime.rb:42:in `run!'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/main.rb:43:in `execute!'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/main.rb:20:in `execute'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/bin/cucumber:14:in `<top (required)>'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/bin/cucumber:19:in `load'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/bin/cucumber:19:in `<main>'
And If I write option in cucumer.yml the error slightly different:
Exception encountered: #<ArgumentError: wrong number of arguments (3 for 2)
Error creating formatter: progress>
backtrace:
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/activerecord-3.1.0/lib/active_record/base.rb:1543:in `initialize'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:168:in `new'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:168:in `block in formatters'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:163:in `map'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:163:in `formatters'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/configuration.rb:68:in `build_tree_walker'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/runtime.rb:42:in `run!'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/cucumber-1.1.0/lib/cucumber/cli/main.rb:43:in `execute!'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/spork-0.9.0.rc9/lib/spork/test_framework/cucumber.rb:24:in `run_tests'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:13:in `block in run'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/spork-0.9.0.rc9/lib/spork/forker.rb:21:in `block in initialize'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/spork-0.9.0.rc9/lib/spork/forker.rb:18:in `fork'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/spork-0.9.0.rc9/lib/spork/forker.rb:18:in `initialize'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:9:in `new'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:9:in `run'
/home/alder/.rvm/gems/ruby-1.9.2-p290#global/gems/spork-0.9.0.rc9/lib/spork/server.rb:48:in `run'
/home/alder/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1558:in `perform_without_block'
/home/alder/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1518:in `perform'
/home/alder/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1592:in `block (2 levels) in main_loop'
/home/alder/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1588:in `loop'
/home/alder/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/drb/drb.rb:1588:in `block in main_loop'
I have a Spork by the way maybe it's a problem.
Based on the updated information in your question, I think I see the problem (hence I'm posting another answer as it's completely different to my other one). It looks like Cucumber is trying to instantiate an ActiveRecord class, so I suspect you have a model named 'Progress' in your project somewhere, which Cucumber is trying to create instead of of the actual formatter.
I was able to reproduce your problem (close enough, anyway) by adding this class in the 'support' folder:
class Progress
def initialize
raise "I don't exist!"
end
end
According to the docs, you should be able to specify a fully qualified class name here i.e. --format Cucumber::Formatter::Progress, to force Cucumber to use it's own formatter. However, I tried this and it still doesn't work, there seems to be a bug in how Cucumber resolves the fully-qualified name.
I was able to get around this by adding this line to my env.rb file:
require 'cucumber/formatter/progress'
Which then allowed me to run cucumber --format progress successfully.
I think that, as env.rb gets executed before any other code, then Cucumber's Progress class will be the first one that gets found when creating the formatter.
It looks from the output you've pasted in, that you have an extra angle ('>') bracket floating around in your cucumber.yml file:
Error creating formatter: progress>
Unless that's a typo in your question, for some reason Cucumber is trying to create a formatter named 'progress>', so you probably just need to find and remove the extra angle bracket.
Edit: This wasn't the problem at all, see my other answer