I'm running mastodon in server(1 core, 4GB RAM).
It sometimes happens deadrock and server error.
I could not find out when to happen this error, but it did multiple times.
A temporary solution is restarting server for now.
What are causes happening this issue? and How to solve it?
Error Log
vendor/bundle/ruby/2.5.0/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:226:in `call'
vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.4/lib/action_dispatch/middleware/cookies.rb:613:in `call'
vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.4/lib/action_dispatch/middleware/callbacks.rb:26:in `block in
/home/mastodon/.rbenv/versions/2.5.0/lib/ruby/2.5.0/delegate.rb:83:in `method_missing'
vendor/bundle/ruby/2.5.0/gems/rack-attack-5.0.1/lib/rack/attack/store_proxy/redis_store_proxy.rb:31:in `in
vendor/bundle/ruby/2.5.0/gems/rack-attack-5.0.1/lib/rack/attack/cache.rb:49:in `do_count'
vendor/bundle/ruby/2.5.0/gems/rack-attack-5.0.1/lib/rack/attack/cache.rb:19:in `count'
vendor/bundle/ruby/2.5.0/gems/rack-attack-5.0.1/lib/rack/attack/throttle.rb:27:in `[]'
vendor/bundle/ruby/2.5.0/gems/rack-attack-5.0.1/lib/rack/attack.rb:89:in `block in throttled?'
vendor/bundle/ruby/2.5.0/gems/rack-attack-5.0.1/lib/rack/attack.rb:88:in `any?'
vendor/bundle/ruby/2.5.0/gems/rack-attack-5.0.1/lib/rack/attack.rb:88:in `throttled?'
vendor/bundle/ruby/2.5.0/gems/rack-attack-5.0.1/lib/rack/attack.rb:143:in `call'
vendor/bundle/ruby/2.5.0/gems/warden-1.2.7/lib/warden/manager.rb:36:in `block in call'
vendor/bundle/ruby/2.5.0/gems/warden-1.2.7/lib/warden/manager.rb:35:in `catch'
vendor/bundle/ruby/2.5.0/gems/warden-1.2.7/lib/warden/manager.rb:35:in `call'
vendor/bundle/ruby/2.5.0/gems/rack-2.0.3/lib/rack/etag.rb:25:in `call'
vendor/bundle/ruby/2.5.0/gems/rack-2.0.3/lib/rack/conditional_get.rb:25:in `call'
vendor/bundle/ruby/2.5.0/gems/rack-2.0.3/lib/rack/head.rb:12:in `call'
vendor/bundle/ruby/2.5.0/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:232:in `context'
vendor/bundle/ruby/2.5.0/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:226:in `call'
vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.4/lib/action_dispatch/middleware/cookies.rb:613:in `call'
vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.4/lib/action_dispatch/middleware/callbacks.rb:26:in `block in
vendor/bundle/ruby/2.5.0/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:97:in `run_callbacks'
vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.4/lib/action_dispatch/middleware/callbacks.rb:24:in `call'
vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.4/lib/action_dispatch/middleware/debug_exceptions.rb:59:in `c
vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.4/lib/action_dispatch/middleware/show_exceptions.rb:31:in `ca
vendor/bundle/ruby/2.5.0/gems/lograge-0.7.1/lib/lograge/rails_ext/rack/logger.rb:15:in `call_app'
vendor/bundle/ruby/2.5.0/gems/railties-5.1.4/lib/rails/rack/logger.rb:24:in `block in call'
vendor/bundle/ruby/2.5.0/gems/activesupport-5.1.4/lib/active_support/tagged_logging.rb:69:in `block in tag
vendor/bundle/ruby/2.5.0/gems/activesupport-5.1.4/lib/active_support/tagged_logging.rb:26:in `tagged'
vendor/bundle/ruby/2.5.0/gems/activesupport-5.1.4/lib/active_support/tagged_logging.rb:69:in `tagged'
vendor/bundle/ruby/2.5.0/gems/railties-5.1.4/lib/rails/rack/logger.rb:24:in `call'
vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.4/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
vendor/bundle/ruby/2.5.0/gems/request_store-1.3.2/lib/request_store/middleware.rb:9:in `call'
vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.4/lib/action_dispatch/middleware/request_id.rb:25:in `call'
vendor/bundle/ruby/2.5.0/gems/rack-2.0.3/lib/rack/method_override.rb:22:in `call'
vendor/bundle/ruby/2.5.0/gems/rack-2.0.3/lib/rack/runtime.rb:22:in `call'
vendor/bundle/ruby/2.5.0/gems/rack-timeout-0.4.2/lib/rack/timeout/core.rb:122:in `block in call'
vendor/bundle/ruby/2.5.0/gems/rack-timeout-0.4.2/lib/rack/timeout/support/timeout.rb:19:in `timeout'
vendor/bundle/ruby/2.5.0/gems/rack-timeout-0.4.2/lib/rack/timeout/core.rb:121:in `call'
vendor/bundle/ruby/2.5.0/gems/actionpack-5.1.4/lib/action_dispatch/middleware/executor.rb:12:in `call'
vendor/bundle/ruby/2.5.0/gems/rack-2.0.3/lib/rack/sendfile.rb:111:in `call'
vendor/bundle/ruby/2.5.0/gems/rack-cors-0.4.1/lib/rack/cors.rb:81:in `call'
vendor/bundle/ruby/2.5.0/gems/railties-5.1.4/lib/rails/engine.rb:522:in `call'
vendor/bundle/ruby/2.5.0/gems/puma-3.11.0/lib/puma/configuration.rb:225:in `call'
vendor/bundle/ruby/2.5.0/gems/puma-3.11.0/lib/puma/server.rb:624:in `handle_request'
vendor/bundle/ruby/2.5.0/gems/puma-3.11.0/lib/puma/server.rb:438:in `process_client'
vendor/bundle/ruby/2.5.0/gems/puma-3.11.0/lib/puma/server.rb:302:in `block in run'
vendor/bundle/ruby/2.5.0/gems/puma-3.11.0/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
method=GET path=/ format=html controller=HomeController action=index status=401 duration=18.72 view=0.00 d
ThreadError (deadlock; recursive locking):
app/models/setting.rb:26:in `[]'
Config file and env variables
#Puma server settings
WEB_CONCURRENCY=0
MAX_THREADS=5
config/puma.rb
threads_count = ENV.fetch('MAX_THREADS') { 5 }.to_i
threads threads_count, threads_count
if ENV['SOCKET'] then
bind 'unix://' + ENV['SOCKET']
else
port ENV.fetch('PORT') { 3000 }
end
environment ENV.fetch('RAILS_ENV') { 'development' }
workers ENV.fetch('WEB_CONCURRENCY') { 0 }
preload_app!
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
plugin :tmp_restart
Thank you in advance.
For me, it was a ruby issue. I was using the wrong version of ruby and I changed the ruby version and it started working after that.
to check the ruby version do:
ruby -v
to change ruby version using rvm
rvm use 2.6.3
Related
I recently started with Rails 6.1 on Windows server. It runs as expected and shows Rails welcome screen. Including the Rails red page if I generate an error in the code.
Then I installed webpack, Yarn etc. and started copying some models from an old application I'd like to reuse. Since then any error in the code breaks Rails: instead of the expected red page, it drops hundreds of lines with the following errors repeated several times:
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/actionview-6.1.4/lib/action_view/template.rb:300: warning: __FILE__ in eval may not return location in binding; use Binding#source_location instead
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/web-console-3.7.0/lib/web_console/exception_mapper.rb:31: warning: in `eval'
And then another bloc:
ArgumentError: wrong number of arguments (given 2, expected 3)
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/actionview-6.1.4/lib/action_view/base.rb:230:in `initialize'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/web-console-3.7.0/lib/web_console/template.rb:21:in `new'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/web-console-3.7.0/lib/web_console/template.rb:21:in `render'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:37:in `block in call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `catch'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/actionpack-6.1.4/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/rack/logger.rb:37:in `call_app'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/rack/logger.rb:26:in `block in call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activesupport-6.1.4/lib/active_support/tagged_logging.rb:99:in `block in tagged'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activesupport-6.1.4/lib/active_support/tagged_logging.rb:37:in `tagged'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activesupport-6.1.4/lib/active_support/tagged_logging.rb:99:in `tagged'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/rack/logger.rb:26:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/quiet_assets.rb:13:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/actionpack-6.1.4/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/actionpack-6.1.4/lib/action_dispatch/middleware/request_id.rb:26:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/activesupport-6.1.4/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/actionpack-6.1.4/lib/action_dispatch/middleware/executor.rb:14:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/actionpack-6.1.4/lib/action_dispatch/middleware/static.rb:24:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/actionpack-6.1.4/lib/action_dispatch/middleware/host_authorization.rb:98:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/webpacker-4.3.0/lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rack-proxy-0.7.0/lib/rack/proxy.rb:63:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/railties-6.1.4/lib/rails/engine.rb:539:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/puma-5.4.0/lib/puma/configuration.rb:249:in `call'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/puma-5.4.0/lib/puma/request.rb:77:in `block in handle_request'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/puma-5.4.0/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/puma-5.4.0/lib/puma/request.rb:76:in `handle_request'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/puma-5.4.0/lib/puma/server.rb:440:in `process_client'
from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/puma-5.4.0/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
What did I break ?
I am trying to deploy a simple Rails 5 application in Heroku which has devise authentication enabled. I have followed a tutorial to deploy the Rails app on Heroku. The app is running and the database is also setup.
When I try to load the initial page of the app, where the user must be redirected to login page, I am getting following exception (in Heroku logs) -
Started GET "/" for 203.187.254.82 at 2018-05-04 10:28:24 +0000
Processing by HomeController#index as HTML
Completed 401 Unauthorized in 1ms
NoMethodError (undefined method `merge' for nil:NilClass):
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/routing/route_set.rb:805:in `url_for'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/routing/route_set.rb:277:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/routing/route_set.rb:218:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/routing/route_set.rb:335:in `block (2 levels) in define_url_helper'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/routing/routes_proxy.rb:42:in `new_user_session_url'
vendor/bundle/ruby/2.3.0/gems/devise-4.4.3/lib/devise/failure_app.rb:153:in `scope_url'
vendor/bundle/ruby/2.3.0/gems/devise-4.4.3/lib/devise/failure_app.rb:128:in `redirect_url'
vendor/bundle/ruby/2.3.0/gems/devise-4.4.3/lib/devise/failure_app.rb:88:in `redirect'
vendor/bundle/ruby/2.3.0/gems/devise-4.4.3/lib/devise/failure_app.rb:43:in `respond'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/abstract_controller/base.rb:186:in `process_action'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/abstract_controller/base.rb:124:in `process'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_controller/metal.rb:189:in `dispatch'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_controller/metal.rb:242:in `block in action'
vendor/bundle/ruby/2.3.0/gems/devise-4.4.3/lib/devise/failure_app.rb:23:in `call'
vendor/bundle/ruby/2.3.0/gems/devise-4.4.3/lib/devise/delegator.rb:7:in `call'
vendor/bundle/ruby/2.3.0/gems/warden-1.2.7/lib/warden/manager.rb:143:in `call_failure_app'
vendor/bundle/ruby/2.3.0/gems/warden-1.2.7/lib/warden/manager.rb:129:in `process_unauthenticated'
vendor/bundle/ruby/2.3.0/gems/warden-1.2.7/lib/warden/manager.rb:44:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/etag.rb:25:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/conditional_get.rb:25:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/head.rb:12:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/session/abstract/id.rb:232:in `context'
vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/session/abstract/id.rb:226:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/cookies.rb:613:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/callbacks.rb:97:in `run_callbacks'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/callbacks.rb:24:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
vendor/bundle/ruby/2.3.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:36:in `call_app'
vendor/bundle/ruby/2.3.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:24:in `block in call'
vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:69:in `block in tagged'
vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:26:in `tagged'
vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:69:in `tagged'
vendor/bundle/ruby/2.3.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:24:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/request_id.rb:25:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.6/lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/executor.rb:12:in `call'
vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/static.rb:125:in `call'
vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
vendor/bundle/ruby/2.3.0/gems/railties-5.1.6/lib/rails/engine.rb:522:in `call'
vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/configuration.rb:225:in `call'
vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/server.rb:632:in `handle_request'
vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/server.rb:446:in `process_client'
vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/server.rb:306:in `block in run'
vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
home_controller.rb
class HomeController < ApplicationController
before_action :authenticate_user!
def index
#activities = nil
end
def posts
#posts = Post.all.order("created_at DESC")
end
end
What am I missing here? Not able to understand whether the exception is from the devise library or my application code.
I have resolved it. I found it from actionpack's code that url_for method requires default_url_options config to be set in respective environment file.
In my case it was in production.rb file.
I had to put-in -
config.action_mailer.default_url_options = { :host => '<YOUR_HEROKU_APP_URL_HERE>' }
I am transitioning from Heroku to AWS Elastic Beanstalk and in my logs I keep seeing this error with .css and .js assets.
Rails 4.2
Ruby 2.2.5
ActionController::RoutingError (No route matches [GET] "/assets/application-be8de4c1a8d12cb784028972b73fe7e23d4acc55757e3d297ef5e3db4161c369.css"):
vendor/bundle/gems/actionpack-4.2.2/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
vendor/bundle/gems/actionpack-4.2.2/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
vendor/bundle/gems/railties-4.2.2/lib/rails/rack/logger.rb:38:in `call_app'
vendor/bundle/gems/railties-4.2.2/lib/rails/rack/logger.rb:20:in `block in call'
vendor/bundle/gems/activesupport-4.2.2/lib/active_support/tagged_logging.rb:68:in `block in tagged'
vendor/bundle/gems/activesupport-4.2.2/lib/active_support/tagged_logging.rb:26:in `tagged'
vendor/bundle/gems/activesupport-4.2.2/lib/active_support/tagged_logging.rb:68:in `tagged'
vendor/bundle/gems/railties-4.2.2/lib/rails/rack/logger.rb:20:in `call'
vendor/bundle/gems/actionpack-4.2.2/lib/action_dispatch/middleware/request_id.rb:21:in `call'
vendor/bundle/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
vendor/bundle/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
vendor/bundle/gems/activesupport-4.2.2/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
vendor/bundle/gems/actionpack-4.2.2/lib/action_dispatch/middleware/static.rb:113:in `call'
vendor/bundle/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
vendor/bundle/gems/actionpack-4.2.2/lib/action_dispatch/middleware/ssl.rb:24:in `call'
vendor/bundle/gems/railties-4.2.2/lib/rails/engine.rb:518:in `call'
vendor/bundle/gems/railties-4.2.2/lib/rails/application.rb:164:in `call'
vendor/bundle/gems/puma-3.6.2/lib/puma/configuration.rb:225:in `call'
vendor/bundle/gems/puma-3.6.2/lib/puma/server.rb:578:in `handle_request'
vendor/bundle/gems/puma-3.6.2/lib/puma/server.rb:415:in `process_client'
vendor/bundle/gems/puma-3.6.2/lib/puma/server.rb:275:in `block in run'
vendor/bundle/gems/puma-3.6.2/lib/puma/thread_pool.rb:116:in `call'
vendor/bundle/gems/puma-3.6.2/lib/puma/thread_pool.rb:116:in `block in spawn_thread'
Help.
Could it be that your configuration file is telling EB to skip asset compilation? See docs here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Ruby.container.html#create_deploy_Ruby.env.console.ruby.envprops
I have Rails 4 app with cucumber features. In some tests i have thinking sphinx data such as:
#javascript #sphinx
Feature: Edit a service
Scenario: Editing
Given I exist as an "individual"
And I have few services as individual user
And Sphinx indexes all models
...
Then I should see I18n translation for key "views.messages.notices.add.updated"
Where #sphinx hook contains this logic:
Before('#sphinx') do
self.use_transactional_fixtures = false
ThinkingSphinx::Test.start
sleep 2 # Give some time for sphinx to start.
end
After('#sphinx') do
ThinkingSphinx::Test.stop
self.use_transactional_fixtures = true
end
And Sphinx indexes all models contains this:
Given(/^Sphinx indexes all models$/) do
ThinkingSphinx::Test.index
# Wait for Sphinx to finish loading in the new index files.
sleep 0.25 until index_finished?
end
Here is database.yml:
development:
adapter: postgresql
database: my-project_development
host: localhost
encoding: UTF8
pool: 5
test: &test
adapter: postgresql
database: my-project_test<%= ENV['TEST_ENV_NUMBER'] %>
username: my-project
password: my-project
host: localhost
encoding: UTF8
pool: 15
When I run my specs via rake parallel:features (via parallel_tests) specs with thinking sphinx ALWAYS fail:
Can't connect to MySQL server on '127.0.0.1' (61) (ThinkingSphinx::ConnectionError)
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/connection.rb:90:in `rescue in query'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/connection.rb:93:in `query'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/connection.rb:75:in `query_all'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/search/batch_inquirer.rb:17:in `block in results'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/connection.rb:37:in `block in take'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/innertube-1.1.0/lib/innertube.rb:138:in `take'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/connection.rb:35:in `take'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/search/batch_inquirer.rb:16:in `results'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/middlewares/inquirer.rb:9:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `block in instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/search/context.rb:22:in `log'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/middlewares/inquirer.rb:8:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/middlewares/geographer.rb:11:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/middlewares/sphinxql.rb:14:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/middleware-0.1.0/lib/middleware/runner.rb:31:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/middleware-0.1.0/lib/middleware/builder.rb:102:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/search.rb:67:in `populate'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/thinking-sphinx-3.1.0/lib/thinking_sphinx/search.rb:113:in `method_missing'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/squeel-1.1.1/lib/squeel/adapters/active_record/relation_extensions.rb:323:in `hash'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/squeel-1.1.1/lib/squeel/adapters/active_record/relation_extensions.rb:323:in `-'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/squeel-1.1.1/lib/squeel/adapters/active_record/relation_extensions.rb:323:in `merge_resolving_duplicate_squeel_equalities'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/squeel-1.1.1/lib/squeel/adapters/active_record/relation_extensions.rb:45:in `merge'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activerecord-4.0.3/lib/active_record/relation.rb:555:in `with_default_scope'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activerecord-4.0.3/lib/active_record/relation.rb:582:in `exec_queries'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activerecord-4.0.3/lib/active_record/relation.rb:471:in `load'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activerecord-4.0.3/lib/active_record/relation.rb:220:in `to_a'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activerecord-4.0.3/lib/active_record/relation.rb:565:in `blank?'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/core_ext/object/blank.rb:20:in `present?'
/Users/serj/Projects/my-project/app/controllers/services_controller.rb:90:in `find_services'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:537:in `_run__1953055605195034856__process_action__callbacks'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/abstract_controller/callbacks.rb:17:in `process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_controller/metal/rescue.rb:29:in `process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `block in instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/notifications.rb:159:in `instrument'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activerecord-4.0.3/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/abstract_controller/base.rb:136:in `process'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/abstract_controller/rendering.rb:44:in `process'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_controller/metal.rb:195:in `dispatch'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_controller/metal.rb:231:in `block in action'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:80:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:48:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:71:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:59:in `each'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/journey/router.rb:59:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/routing/route_set.rb:680:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-pjax-0.7.0/lib/rack/pjax.rb:12:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/request_store-1.0.5/lib/request_store/middleware.rb:9:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/simple_captcha2-0.2.1/lib/simple_captcha/middleware.rb:20:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/remotipart-1.2.1/lib/remotipart/middleware.rb:27:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/flash.rb:241:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/cookies.rb:486:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activerecord-4.0.3/lib/active_record/query_cache.rb:36:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activerecord-4.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:373:in `_run__4201420912784056511__call__callbacks'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/callbacks.rb:80:in `run_callbacks'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/cucumber-rails-1.4.0/lib/cucumber/rails/action_controller.rb:10:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/railties-4.0.3/lib/rails/rack/logger.rb:38:in `call_app'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:67:in `block in tagged'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:25:in `tagged'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/tagged_logging.rb:67:in `tagged'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/activesupport-4.0.3/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/actionpack-4.0.3/lib/action_dispatch/middleware/static.rb:64:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/railties-4.0.3/lib/rails/engine.rb:511:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/railties-4.0.3/lib/rails/application.rb:97:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/urlmap.rb:65:in `block in call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `each'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/capybara-2.2.1/lib/capybara/server.rb:19:in `call'
/Users/serj/.rvm/gems/ruby-2.0.0-p353#my-project/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
/Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
But if I run these failed tests in non parallel mode (I mean cucumber path/to/my/test.rb), it works (and yes, parallel_tests works well for the other tests). How can I solve this trouble?
You'll want to configure config/thinking_sphinx.yml to include that environment variable TEST_ENV_NUMBER in the paths for Sphinx files - the settings listed in the deployment page of the docs should be what's required, plus the port number (the mysql41 setting) as well. Perhaps something like this?
test:
mysql41: <%= ENV['TEST_ENV_NUMBER'].to_i + 9307 %>
pid_file: /path/to/app/tmp/searchd.<%= ENV['TEST_ENV_NUMBER' %>.pid
indices_location: /path/to/app/db/sphinx/<%= ENV['TEST_ENV_NUMBER' %>
configuration_file: /path/to/app/config/test.<%= ENV['TEST_ENV_NUMBER' %>.sphinx.conf
binlog_path: /path/to/app/db/sphinx/<%= ENV['TEST_ENV_NUMBER' %>/binlog
I've not used this approach (or parallel_test) myself, so this is certainly guesswork, but it's worth a shot.
For the last month, we've had a bot scraping our site regularly, leading to a bunch of ArgumentError: invalid %-encoding errors because the URLs are malformed. I've looked at a bunch of issues in rack here and here and rails here, and looked at this SO thread but there doesn't seem to be a definitive solution. Is there a correct solution for GET errors? Do I have to monkeypatch rack?
edit: And here's a backtrace:
/usr/local/lib/ruby/1.9.1/uri/common.rb:898:in `decode_www_form_component'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:41:in `unescape'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:94:in `block (2 levels) in parse_nested_query'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:94:in `map'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:94:in `block in parse_nested_query'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:93:in `each'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/utils.rb:93:in `parse_nested_query'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/request.rb:332:in `parse_query'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/http/request.rb:269:in `parse_query'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/request.rb:186:in `GET'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/http/request.rb:225:in `GET'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/http/parameters.rb:10:in `parameters'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/http/filter_parameters.rb:33:in `filtered_parameters'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:21:in `process_action'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
[GEM_ROOT]/gems/activerecord-3.2.12/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/abstract_controller/base.rb:121:in `process'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/abstract_controller/rendering.rb:45:in `process'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_controller/metal.rb:203:in `dispatch'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_controller/metal.rb:246:in `block in action'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:73:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:36:in `call'
[GEM_ROOT]/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
[GEM_ROOT]/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
[GEM_ROOT]/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:601:in `call'
[GEM_ROOT]/gems/omniauth-1.1.1/lib/omniauth/strategy.rb:177:in `call!'
[GEM_ROOT]/gems/omniauth-1.1.1/lib/omniauth/strategy.rb:157:in `call'
[GEM_ROOT]/gems/sass-3.2.7/lib/sass/plugin/rack.rb:54:in `call'
[GEM_ROOT]/gems/warden-1.2.1/lib/warden/manager.rb:35:in `block in call'
[GEM_ROOT]/gems/warden-1.2.1/lib/warden/manager.rb:34:in `catch'
[GEM_ROOT]/gems/warden-1.2.1/lib/warden/manager.rb:34:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/etag.rb:23:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/conditionalget.rb:25:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/head.rb:14:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/flash.rb:242:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210:in `context'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/cookies.rb:341:in `call'
[GEM_ROOT]/gems/activerecord-3.2.12/lib/active_record/query_cache.rb:64:in `call'
[GEM_ROOT]/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `_run__497203393471184793__call__4495106819278994598__callbacks'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/rack/logger.rb:32:in `call_app'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `block in call'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/tagged_logging.rb:22:in `tagged'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/rack/logger.rb:16:in `call'
[GEM_ROOT]/gems/actionpack-3.2.12/lib/action_dispatch/middleware/request_id.rb:22:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
[GEM_ROOT]/gems/activesupport-3.2.12/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:143:in `pass'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:172:in `rescue in lookup'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:168:in `lookup'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/engine.rb:479:in `call'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/application.rb:223:in `call'
[GEM_ROOT]/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/utils.rb:479:in `safe_fork'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server.rb:180:in `start'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.13/helper-scripts/passenger-spawn-server:99:in `<main>'
if you don't mind against monkeypatching Rack then create in config/initializers file (for example rack.rb) with this content:
module Rack
module Utils
if defined?(::Encoding)
def unescape(s, encoding = Encoding::UTF_8)
begin
URI.decode_www_form_component(s, encoding)
rescue ArgumentError
URI.decode_www_form_component(URI.encode(s), encoding)
end
end
else
def unescape(s, encoding = nil)
begin
URI.decode_www_form_component(s, encoding)
rescue ArgumentError
URI.decode_www_form_component(URI.encode(s), encoding)
end
end
end
module_function :unescape
end
end
p.s. it works with passenger, but with Webrick and Thin it doesn't. It looks like both webrick and thin parse a request too, so the failure happens before initializer is loaded. For example with Thin error happens in thin-1.6.2/lib/thin/request.rb:84.
You could inject a middleware designed to detect these and fail gracefully. The basic idea is to just try to parse the query string, and if it fails, bail out with a HTTP 400. Otherwise, just allow the request through.
class RefuseInvalidRequest
def initialize(app)
#app = app
end
def call(env)
query = Rack::Utils.parse_nested_query(env['QUERY_STRING'].to_s) rescue :bad_query
if query == :bad_query
[400, {'Content-Type' => 'text/plain'}, "Bad Request"]
else
#app.call(env)
end
end
end
I haven't tested this, but the concept should work.