I'm pretty new to Elasticsearch and i'm running into this error.
Elasticsearch::Transport::Transport::Errors::ServiceUnavailable at /search
[503] {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed]","status":503}
This is the complete error log
Elasticsearch::Transport::Transport::Errors::ServiceUnavailable - [503] {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed]","status":503}:
elasticsearch-transport (1.0.5) lib/elasticsearch/transport/transport/base.rb:132:in `__raise_transport_error'
elasticsearch-transport (1.0.5) lib/elasticsearch/transport/transport/base.rb:224:in `perform_request'
elasticsearch-transport (1.0.5) lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
elasticsearch-transport (1.0.5) lib/elasticsearch/transport/client.rb:104:in `perform_request'
elasticsearch-api (1.0.5) lib/elasticsearch/api/actions/search.rb:158:in `search'
elasticsearch-model (0.1.6) lib/elasticsearch/model/searching.rb:51:in `execute!'
elasticsearch-model (0.1.6) lib/elasticsearch/model/response.rb:31:in `response'
elasticsearch-model (0.1.6) lib/elasticsearch/model/response/records.rb:34:in `ids'
elasticsearch-model (0.1.6) lib/elasticsearch/model/adapters/active_record.rb:16:in `records'
elasticsearch-model (0.1.6) lib/elasticsearch/model/response/records.rb:64:in `respond_to?'
activesupport (4.1.4) lib/active_support/core_ext/object/blank.rb:17:in `blank?'
activesupport (4.1.4) lib/active_support/core_ext/object/blank.rb:24:in `present?'
() home/pavan/Roorah/app/controllers/visitors_controller.rb:34:in `search'
actionpack (4.1.4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.4) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.1.4) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:229:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:86:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:86:in `run_callbacks'
actionpack (4.1.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.1.4) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.4) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.1.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.1.4) lib/abstract_controller/base.rb:136:in `process'
actionview (4.1.4) lib/action_view/rendering.rb:30:in `process'
actionpack (4.1.4) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.1.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.4) lib/action_controller/metal.rb:232:in `block in action'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:82:in `call'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.1.4) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.1.4) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.4) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:678:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/rack/error_collector.rb:50:in `traced_call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/rack/agent_hooks.rb:26:in `traced_call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/rack/browser_monitoring.rb:23:in `traced_call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/rack/developer_mode.rb:48:in `traced_call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/flash.rb:254:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
activerecord (4.1.4) lib/active_record/query_cache.rb:36:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
activerecord (4.1.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
activerecord (4.1.4) lib/active_record/migration.rb:380:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.4) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
better_errors (2.0.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.0.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.0.0) lib/better_errors/middleware.rb:57:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
railties (4.1.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.4) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.0.3) lib/quiet_assets.rb:23:in `call_with_quiet_assets'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
activesupport (4.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/static.rb:64:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
railties (4.1.4) lib/rails/engine.rb:514:in `call'
railties (4.1.4) lib/rails/application.rb:144:in `call'
newrelic_rpm (3.9.5.251) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
thin (1.6.3) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.6.3) lib/thin/connection.rb:84:in `catch'
thin (1.6.3) lib/thin/connection.rb:84:in `pre_process'
thin (1.6.3) lib/thin/connection.rb:53:in `process'
thin (1.6.3) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
thin (1.6.3) lib/thin/backends/base.rb:73:in `start'
thin (1.6.3) lib/thin/server.rb:162:in `start'
rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
rack (1.5.2) lib/rack/server.rb:264:in `start'
railties (4.1.4) lib/rails/commands/server.rb:69:in `start'
railties (4.1.4) lib/rails/commands/commands_tasks.rb:81:in `block in server'
railties (4.1.4) lib/rails/commands/commands_tasks.rb:76:in `tap'
railties (4.1.4) lib/rails/commands/commands_tasks.rb:76:in `server'
railties (4.1.4) lib/rails/commands/commands_tasks.rb:40:in `run_command!'
railties (4.1.4) lib/rails/commands.rb:17:in `<top (required)>'
() home/pavan/Roorah/bin/rails:8:in `require'
() home/pavan/Roorah/bin/rails:8:in `<top (required)>'
spring (1.1.3) lib/spring/client/rails.rb:27:in `load'
spring (1.1.3) lib/spring/client/rails.rb:27:in `call'
spring (1.1.3) lib/spring/client/command.rb:7:in `call'
spring (1.1.3) lib/spring/client.rb:26:in `run'
spring (1.1.3) bin/spring:48:in `<top (required)>'
spring (1.1.3) lib/spring/binstub.rb:11:in `load'
spring (1.1.3) lib/spring/binstub.rb:11:in `<top (required)>'
() home/pavan/Roorah/bin/spring:16:in `require'
() home/pavan/Roorah/bin/spring:16:in `<top (required)>'
() rails:3:in `load'
() rails:3:in `<main>'
This is the piece of code from visitors_controller.rb believed to be the reason behind the error.
#search_results = Property.where(property_active: true)
### new search
results = CityCoordinate.search(params[:q]).records
if params[:q].present? && results.present? #line 34
latitude = results.first.latitude
longitude = results.first.longitude
city = Property.new("latitude" => latitude, "longitude" => longitude)
#search_results = city.nearbys(200).where(property_active: true)
end
###
These are request parameters
{"utf8"=>"✓", "q"=>"Holtsville, NY, United States", "min"=>"", "max"=>"", "baths"=>"", "beds"=>"", "property_type"=>"", "pet"=>"", "garage"=>"", "controller"=>"visitors", "action"=>"search"}
Update:
Below is the log of things which are executed while search
Started GET "/search?utf8=%E2%9C%93&q=Holtsville%2C+NY%2C+United+States&min=&max=&baths=&beds=&property_type=&pet=&garage=" for 127.0.0.1 at 2015-03-16 09:53:30 +0530
Processing by VisitorsController#search as HTML
Parameters: {"utf8"=>"✓", "q"=>"Holtsville, NY, United States", "min"=>"", "max"=>"", "baths"=>"", "beds"=>"", "property_type"=>"", "pet"=>"", "garage"=>""}
CityCoordinate Load (283.1ms) SELECT "city_coordinates".* FROM "city_coordinates" ORDER BY "city_coordinates"."id" ASC LIMIT 1000
2015-03-16 09:54:30 +0530: POST http://localhost:9200/city_coordinates/city_coordinate/_bulk?type=city_coordinate [status:200, request:60.010s, query:60.005s]
2015-03-16 09:54:30 +0530: > {"index":{"_id":1}}
{"id":1,"latitude":40.81,"longitude":-73.04,"zipcode":544,"city":"Holtsville","state":"NY","created_at":"2015-03-10T06:21:50.061Z","updated_at":"2015-03-10T06:21:50.061Z"}
{"index":{"_id":2}}
{"id":2,"latitude":18.16,"longitude":-66.72,"zipcode":601,"city":"Adjuntas","state":"PR","created_at":"2015-03-10T06:21:50.120Z","updated_at":"2015-03-10T06:21:50.120Z"}
2015-03-16 09:54:30 +0530: < {"took":60005,"errors":true,"items":[{"index":{"_index":"city_coordinates","_type":"city_coordinate","_id":"1","status":503,"error":"UnavailableShardsException[[city_coordinates][2] Primary shard is not active or isn't assigned is a known node. Timeout: [1m], request: org.elasticsearch.action.bulk.BulkShardRequest#5f0340e0]"}},{"index":{"_index":"city_coordinates","_type":"city_coordinate","_id":"2","status":503,"error":"UnavailableShardsException[[city_coordinates][3] Primary shard is not active or isn't assigned is a known node. Timeout: [1m], request: org.elasticsearch.action.bulk.BulkShardRequest#2d813d7b]"}}]}
2015-03-16 09:54:30 +0530: GET http://localhost:9200/city_coordinates/city_coordinate/_search?q=Holtsville%2C+NY%2C+United+States [status:503, request:0.028s, query:N/A]
2015-03-16 09:54:30 +0530: < {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed]","status":503}
2015-03-16 09:54:30 +0530: [503] {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed]","status":503}
Completed 500 Internal Server Error in 60402ms
Log from elasticsearch
pavan#Pavan-Inspiron-3542:~/elasticsearch-1.4.4/bin$ ./elasticsearch
[2015-03-16 09:49:18,455][INFO ][node ] [Ant-Man] version[1.4.4], pid[2980], build[c88f77f/2015-02-19T13:05:36Z]
[2015-03-16 09:49:18,499][INFO ][node ] [Ant-Man] initializing ...
[2015-03-16 09:49:18,518][INFO ][plugins ] [Ant-Man] loaded [], sites []
[2015-03-16 09:49:22,526][INFO ][node ] [Ant-Man] initialized
[2015-03-16 09:49:22,527][INFO ][node ] [Ant-Man] starting ...
[2015-03-16 09:49:22,711][INFO ][transport ] [Ant-Man] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/10.0.1.20:9300]}
[2015-03-16 09:49:22,740][INFO ][discovery ] [Ant-Man] elasticsearch/lZbmLwgxTdC9zwU0qcYrUw
[2015-03-16 09:49:26,516][INFO ][cluster.service ] [Ant-Man] new_master [Ant-Man][lZbmLwgxTdC9zwU0qcYrUw][Pavan-Inspiron-3542][inet[/10.0.1.20:9300]], reason: zen-disco-join (elected_as_master)
[2015-03-16 09:49:26,532][INFO ][http ] [Ant-Man] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/10.0.1.20:9200]}
[2015-03-16 09:49:26,532][INFO ][node ] [Ant-Man] started
[2015-03-16 09:49:27,317][INFO ][gateway ] [Ant-Man] recovered [2] indices into cluster_state
[2015-03-16 09:54:30,813][DEBUG][action.bulk ] [Ant-Man] observer: timeout notification from cluster service. timeout setting [1m], time since start [1m]
[2015-03-16 09:54:30,815][DEBUG][action.bulk ] [Ant-Man] observer: timeout notification from cluster service. timeout setting [1m], time since start [1m]
[2015-03-16 09:54:30,847][DEBUG][action.search.type ] [Ant-Man] All shards failed for phase: [query]
And i have these in the Gemfile
gem 'elasticsearch-model', '0.1.6'
gem 'elasticsearch-rails', '0.1.6'
gem 'bonsai-elasticsearch-rails', '0.0.4'
I can't figure what is happening and i'm stuck with this.In our rails app we use elasticsearch for the renters to search for the properties posted by the landlords with the city,state and country being the parameters of q. Currently there is a property with the given city Holtsville.
Please do ask if any information is required.
Update 1:
The output when i run curl -X GET 'http://localhost:9200/_cat/shards?v&pretty'
pavan#Pavan-Inspiron-3542:~/elasticsearch-1.4.4/bin$ curl -X GET 'http://localhost:9200/_cat/shards?v&pretty'
index shard prirep state docs store ip node
city_coordinates 2 p UNASSIGNED
city_coordinates 2 r UNASSIGNED
city_coordinates 0 p UNASSIGNED
city_coordinates 0 r UNASSIGNED
city_coordinates 3 p UNASSIGNED
city_coordinates 3 r UNASSIGNED
city_coordinates 1 p UNASSIGNED
city_coordinates 1 r UNASSIGNED
city_coordinates 4 p UNASSIGNED
city_coordinates 4 r UNASSIGNED
properties 4 p UNASSIGNED
properties 4 r UNASSIGNED
properties 0 p STARTED 0 115b 127.0.1.1 Franz Kafka
properties 0 r UNASSIGNED
properties 3 p UNASSIGNED
properties 3 r UNASSIGNED
properties 1 p STARTED 0 115b 127.0.1.1 Franz Kafka
properties 1 r UNASSIGNED
properties 2 p STARTED 1 7.3kb 127.0.1.1 Franz Kafka
properties 2 r UNASSIGNED
Update 2:
I uncommented and added these things in elasticsearch.yml file
node.name: "Franz Kafka"
node.master: true
node.data: true
cluster.routing.allocation.disk.threshold_enabled: true
cluster.routing.allocation.disk.watermark.low: 97
cluster.routing.allocation.disk.watermark.high: 99
bootstrap.mlockall: true
network.bind_host: localhost
script.disable_dynamic: true
network.publish_host: localhost
And i created an executable file called elasticsearch in /etc/init.d to add these environment variables
ES_MIN_MEM=256m
ES_MAX_MEM=1g
Update 3:
The output when i run curl -XGET http://localhost:9200/_cluster/health?pretty
pavan#Pavan-Inspiron-3542:~/elasticsearch-1.4.4/bin$ curl -XGET http://localhost:9200/_cluster/health?pretty
{
"cluster_name" : "elasticsearch",
"status" : "red",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 3,
"active_shards" : 3,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 17
}
Update 4:
According to this link,it seems like my machine didn't have the minimum 8GB of RAM(I have 4GB). Is this the reason for the error? And also the city_coordinates table(which the elasticsearch collects the data from) has 43k records which gives me enough reason to believe that the current memory(4GB) is not sufficient for elasticsearch.
Update 5:
The output when i run curl 'localhost:9200/_cat/nodes?v'
pavan#Pavan-Inspiron-3542:~/elasticsearch-1.4.4/bin$ curl 'localhost:9200/_cat/nodes?v'
host ip heap.percent ram.percent load node.role master name
Pavan-Inspiron-3542 127.0.1.1 6 41 0.49 d * Franz Kafka
Your problem is logged here:
Primary shard is not active or isn't assigned is a known node.
This usually means that Elasticsearch is unable to create the primary shard for your index. Often, this is because your disk is too full:
cluster.routing.allocation.disk.watermark.low controls the low watermark for disk usage. It defaults to 85%, meaning ES will not allocate new shards to nodes once they have more than 85% disk used.
http://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-allocation.html
You should probably set your Elasticsearch log level to DEBUG for more information.
Edit: Based on your shard debug output, it looks like you've created your index with 20 shards, but your nodes won't accomodate that many.
The index.routing.allocation.total_shards_per_node setting allows to control how many total shards (replicas and primaries) for an index will be allocated per node.
You should recreate your index with number_of_replicas and number_of_shards set to values such that number_of_shards * number_of_replicas is less than index.routing.allocation.total_shards_per_node, and number_of_replicas is no larger than the number of nodes in your cluster.
http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
Related
I am getting SQL-injection url requests such as: ?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=12345.php&vars[1][1]=
which is causing a:
ActionController::BadRequest (Invalid query parameters: expected Hash (got Array) for param `1'):
in my home#index. I believe the error is caught in a middleware or routing as I cannot catch the error in the home#index controller (or application controller either).
This is my development log response to the url:
ActionController::BadRequest (Invalid query parameters: expected Hash (got Array) for param `1'):
rack (1.6.11) lib/rack/utils.rb:162:in `normalize_params'
rack (1.6.11) lib/rack/utils.rb:163:in `normalize_params'
rack (1.6.11) lib/rack/utils.rb:122:in `block in parse_nested_query'
rack (1.6.11) lib/rack/utils.rb:119:in `each'
rack (1.6.11) lib/rack/utils.rb:119:in `parse_nested_query'
rack (1.6.11) lib/rack/request.rb:371:in `parse_query'
actionpack (4.2.10) lib/action_dispatch/http/request.rb:339:in `parse_query'
rack (1.6.11) lib/rack/request.rb:191:in `GET'
actionpack (4.2.10) lib/action_dispatch/http/request.rb:300:in `GET'
actionpack (4.2.10) lib/action_dispatch/http/parameters.rb:14:in `parameters'
actionpack (4.2.10) lib/action_dispatch/http/filter_parameters.rb:37:in `filtered_parameters'
actionpack (4.2.10) lib/action_controller/metal/instrumentation.rb:22:in `process_action'
actionpack (4.2.10) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.10) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.10) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.10) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.10) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.10) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.10) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.10) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
actionpack (4.2.10) lib/action_dispatch/routing/route_set.rb:43:in `serve'
actionpack (4.2.10) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.10) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.10) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.10) lib/action_dispatch/routing/route_set.rb:817:in `call'
bullet (6.0.2) lib/bullet/rack.rb:12:in `call'
rack (1.6.11) lib/rack/etag.rb:24:in `call'
rack (1.6.11) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.11) lib/rack/head.rb:13:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.11) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.11) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.10) lib/active_record/query_cache.rb:36:in `call'
airbrake (9.4.3) lib/airbrake/rack/middleware.rb:32:in `call!'
airbrake (9.4.3) lib/airbrake/rack/middleware.rb:21:in `call'
activerecord (4.2.10) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.10) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.10) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.10) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.10) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.10) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.10) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.10) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.10) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.10) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.10) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.10) lib/rails/rack/logger.rb:20:in `call'
request_store (1.4.1) lib/request_store/middleware.rb:19:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.11) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.11) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.10) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.11) lib/rack/lock.rb:17:in `call'
actionpack (4.2.10) lib/action_dispatch/middleware/static.rb:120:in `call'
rack (1.6.11) lib/rack/sendfile.rb:113:in `call'
utf8-cleaner (0.2.5) lib/utf8-cleaner/middleware.rb:21:in `call'
railties (4.2.10) lib/rails/engine.rb:518:in `call'
railties (4.2.10) lib/rails/application.rb:165:in `call'
rack (1.6.11) lib/rack/content_length.rb:15:in `call'
thin (1.7.2) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.7.2) lib/thin/connection.rb:84:in `catch'
thin (1.7.2) lib/thin/connection.rb:84:in `pre_process'
thin (1.7.2) lib/thin/connection.rb:53:in `process'
thin (1.7.2) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.2.7) lib/eventmachine.rb:195:in `run_machine'
eventmachine (1.2.7) lib/eventmachine.rb:195:in `run'
thin (1.7.2) lib/thin/backends/base.rb:73:in `start'
thin (1.7.2) lib/thin/server.rb:162:in `start'
rack (1.6.11) lib/rack/handler/thin.rb:19:in `run'
rack (1.6.11) lib/rack/server.rb:287:in `start'
railties (4.2.10) lib/rails/commands/server.rb:80:in `start'
railties (4.2.10) lib/rails/commands/commands_tasks.rb:80:in `block in server'
railties (4.2.10) lib/rails/commands/commands_tasks.rb:75:in `tap'
railties (4.2.10) lib/rails/commands/commands_tasks.rb:75:in `server'
railties (4.2.10) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
railties (4.2.10) lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:9:in `require'
bin/rails:9:in `<top (required)>'
spring (2.1.0) lib/spring/client/rails.rb:28:in `load'
spring (2.1.0) lib/spring/client/rails.rb:28:in `call'
spring (2.1.0) lib/spring/client/command.rb:7:in `call'
spring (2.1.0) lib/spring/client.rb:30:in `run'
spring (2.1.0) bin/spring:49:in `<top (required)>'
spring (2.1.0) lib/spring/binstub.rb:11:in `load'
spring (2.1.0) lib/spring/binstub.rb:11:in `<top (required)>'
bin/spring:13:in `require'
bin/spring:13:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
How can I make sure these spam/sql inject-requests are being handled so they don't cause exceptions?
In Your Application Controller:
rescue_from ActionController::BadRequest, with: :bad_request
def bad_request(exception)
render status: 400, json: {:error => exception.message}.to_json
end
I came across this same issue this evening. The error is being thrown before ApplicationController begins to handle the request so catching it in ApplicationController won't work because it's too late.
What you need to do is insert a piece of middleware that catches ActionController::BadRequest before the ActionDispatch::ParamsParser middleware which is throwing the error.
Example which catches the error, adds it to the log and then returns a plain text 400 page.
# app/middleware/catch_batch_request_error_mw.rb
class CatchBadRequestErrorMw
def initialize(app)
#app = app
end
def call(env)
begin
#app.call(env)
rescue ActionController::BadRequest => e
Rails.logger.error("CatchBadRequestErrorMw: #{e.message}")
return [
400,
{
'Content-Type': 'text/plain',
},
['Bad Request']
]
end
end
end
And then in Application.rb
config.middleware.insert_before(ActionDispatch::ParamsParser, CatchBadRequestErrorMw)
I should note that the examples here are from a Rails 4.2 app so if you have any issues I'd start there.
I have uninstalled and installed PG and all the pg related gems. When i try to run the rails server i am getting the following error
rails s
=> Booting WEBrick
=> Rails 4.2.5.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-03-02 22:23:01] INFO WEBrick 1.3.1
[2016-03-02 22:23:01] INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin14]
[2016-03-02 22:23:01] INFO WEBrick::HTTPServer#start: pid=6351 port=3000
Started GET "/" for ::1 at 2016-03-02 22:23:06 +0530
PG::ConnectionBad - could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
:
activerecord (4.2.5.2) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
activerecord (4.2.5.2) lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
activerecord (4.2.5.2) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/Users/harshamv/.rbenv/versions/2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/Users/harshamv/.rbenv/versions/2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
activerecord (4.2.5.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
activerecord (4.2.5.2) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
activerecord (4.2.5.2) lib/active_record/connection_handling.rb:87:in `connection'
activerecord (4.2.5.2) lib/active_record/migration.rb:383:in `connection'
activerecord (4.2.5.2) lib/active_record/migration.rb:370:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (4.2.5.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.5.2) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.5.2) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.5.2) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (4.2.5.2) lib/action_dispatch/middleware/reloader.rb:73:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (4.2.5.2) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (4.2.5.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack-contrib (1.4.0) lib/rack/contrib/response_headers.rb:17:in `call'
meta_request (0.4.0) lib/meta_request/middlewares/headers.rb:16:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (4.2.5.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
railties (4.2.5.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.5.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.5.2) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.5.2) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.5.2) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.5.2) lib/rails/rack/logger.rb:20:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (4.2.5.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
activesupport (4.2.5.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
actionpack (4.2.5.2) lib/action_dispatch/middleware/static.rb:116:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
railties (4.2.5.2) lib/rails/engine.rb:518:in `call'
railties (4.2.5.2) lib/rails/application.rb:165:in `call'
newrelic_rpm (3.15.0.314) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
/Users/harshamv/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/harshamv/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/harshamv/.rbenv/versions/2.2.2/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Started POST "/__better_errors/6febe33a854ba104/variables" for ::1 at 2016-03-02 22:23:06 +0530
The server.log in postgres shows the following
DETAIL: Permissions should be u=rwx (0700).
FATAL: data directory "/usr/local/var/postgres" has group or world access
DETAIL: Permissions should be u=rwx (0700).
FATAL: data directory "/usr/local/var/postgres" has group or world access
DETAIL: Permissions should be u=rwx (0700).
FATAL: data directory "/usr/local/var/postgres" has group or world access
DETAIL: Permissions should be u=rwx (0700).
FATAL: data directory "/usr/local/var/postgres" has group or world access
DETAIL: Permissions should be u=rwx (0700).
On restarting the brew services
➜ postgres git:(master) brew services postgres restart
==> Tapping homebrew/services
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 7 (delta 0), reused 4 (delta 0), pack-reused 0
Unpacking objects: 100% (7/7), done.
Checking connectivity... done.
Tapped 0 formulae (32 files, 42.0K)
Error: No available formula with the name "restart"
This error usually comes when postgres server is not up. Try restarting postgres service. You can restart postgres using command:
sudo service postgresql restart
I am using the gem 'bootstrap3-datetimepicker-rails', '~> 4.17' so that the user can select a date and time, which is passed to my controller and included in the model's attributes. However, when I add load_and_authorize_resource to the controller (using cancancan), I get the following error.
argument out of range
The error is happening because it is passing the date January 27, 2015, but the date and month numbers are switched, and it doesn't like getting a date with month=27, hence the out of range error. However, this error is not happening in my controller, and the whole process works fine when I remove load_and_authorize_resource from the controller.
How can I get this working (avoiding the error) while still authorizing the controller with cancancan?
I am using Rails 4.1.4 and Ruby 2.0.0. Any guidance would be much appreciated, thanks!
Edit: Adding code.
damages/new.html.erb
<%= simple_form_for([#car, #damage], html: {class: 'create-damage-form'}) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<span class='input-group date damage-datepicker'>
<%= f.text_field :date_of_damage, class: "form-control" %>
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</span>
</br>
<%= f.text_area :description, class: 'form-control form-solo-field', placeholder: 'Enter a description of the damage...' %>
</div>
<div class="form-actions">
</br>
<%= f.submit "Submit", class: "btn btn-primary btn-md" %>
</div>
<% end %>
damages_controller.rb
def create
if !params[:damage][:date_of_damage].nil?
date_of_damage = params[:damage][:date_of_damage]
else
redirect_to :back, alert: 'Enter the date of damage.'
return
end
begin
# auth_time = DateTime.strptime(auth_time, "%m-%d-%Y %H:%M%S")
date_of_damage = DateTime.strptime(date_of_damage,'%m/%d/%Y')
rescue ArgumentError => e
redirect_to :back, alert: 'Enter a valid date.'
return
end
#car = Car.find(params[:car_id])
damage_params_with_date = damage_params
damage_params_with_date[:date_of_damage] = date_of_damage
#damage = #car.damages.build(damage_params_with_date)
respond_to do |format|
if #damage.save
format.html { redirect_to #car, notice: 'Damage record was successfully added.' }
format.json { render :show, status: :created, location: #car }
else
format.html { redirect_to :back, alert: 'Damage record was not added.' }
format.json { render json: #damage.errors, status: :unprocessable_entity }
end
end
end
partner_ability.rb
can :manage, Damage, :car_id => #partner.car_ids
can :create, Damage
Stack Trace:
Started POST "/cars/1/damages" for 127.0.0.1 at 2016-01-28 22:55:22 -0500
Processing by DamagesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"gc5CPvSxAjwJfX4ekjEuJ1eZml9aoPxQWPfTBC2/kfc=", "damage"=>{"date_of_damage"=>"01/28/2016 10:55 PM", "description"=>"test"}, "commit"=>"Submit", "car_id"=>"1"}
Completed 500 Internal Server Error in 5ms
ArgumentError - argument out of range:
activesupport (4.1.4) lib/active_support/values/time_zone.rb:289:in `parse'
activesupport (4.1.4) lib/active_support/core_ext/string/zones.rb:9:in `in_time_zone'
activerecord (4.1.4) lib/active_record/attribute_methods/time_zone_conversion.rb:37:in `date_of_damage='
activerecord (4.1.4) lib/active_record/attribute_assignment.rb:45:in `_assign_attribute'
activerecord (4.1.4) lib/active_record/attribute_assignment.rb:32:in `block in assign_attributes'
activerecord (4.1.4) lib/active_record/attribute_assignment.rb:26:in `assign_attributes'
activerecord (4.1.4) lib/active_record/core.rb:455:in `init_attributes'
activerecord (4.1.4) lib/active_record/core.rb:198:in `initialize'
activerecord (4.1.4) lib/active_record/inheritance.rb:30:in `new'
cancancan (1.13.1) lib/cancan/controller_resource.rb:80:in `build_resource'
cancancan (1.13.1) lib/cancan/controller_resource.rb:61:in `load_resource_instance'
cancancan (1.13.1) lib/cancan/controller_resource.rb:32:in `load_resource'
cancancan (1.13.1) lib/cancan/controller_resource.rb:25:in `load_and_authorize_resource'
cancancan (1.13.1) lib/cancan/controller_resource.rb:10:in `block in add_before_filter'
activesupport (4.1.4) lib/active_support/callbacks.rb:440:in `block in make_lambda'
activesupport (4.1.4) lib/active_support/callbacks.rb:160:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:86:in `run_callbacks'
actionpack (4.1.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.1.4) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.4) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.1.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.1.4) lib/abstract_controller/base.rb:136:in `process'
actionview (4.1.4) lib/action_view/rendering.rb:30:in `process'
actionpack (4.1.4) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.1.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.4) lib/action_controller/metal.rb:232:in `block in action'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.1.4) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.1.4) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:678:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
meta_request (0.3.4) lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
meta_request (0.3.4) lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/rack/browser_monitoring.rb:32:in `traced_call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/rack/developer_mode.rb:48:in `traced_call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
rack (1.5.5) lib/rack/etag.rb:23:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
rack (1.5.5) lib/rack/conditionalget.rb:35:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
rack (1.5.5) lib/rack/head.rb:11:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/flash.rb:254:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
rack (1.5.5) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.5) lib/rack/session/abstract/id.rb:220:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
activerecord (4.1.4) lib/active_record/query_cache.rb:36:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
activerecord (4.1.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
activerecord (4.1.4) lib/active_record/migration.rb:380:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.4) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
rack-contrib (1.4.0) lib/rack/contrib/response_headers.rb:17:in `call'
meta_request (0.3.4) lib/meta_request/middlewares/headers.rb:16:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
railties (4.1.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.4) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
rack (1.5.5) lib/rack/methodoverride.rb:21:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
rack (1.5.5) lib/rack/runtime.rb:17:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
activesupport (4.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
rack (1.5.5) lib/rack/lock.rb:17:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/static.rb:64:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
rack (1.5.5) lib/rack/sendfile.rb:112:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
railties (4.1.4) lib/rails/engine.rb:514:in `call'
railties (4.1.4) lib/rails/application.rb:144:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
rack (1.5.5) lib/rack/content_length.rb:14:in `call'
thin (1.6.4) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.6.4) lib/thin/connection.rb:84:in `pre_process'
thin (1.6.4) lib/thin/connection.rb:53:in `process'
thin (1.6.4) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.0.8) lib/eventmachine.rb:193:in `run'
thin (1.6.4) lib/thin/backends/base.rb:73:in `start'
thin (1.6.4) lib/thin/server.rb:162:in `start'
rack (1.5.5) lib/rack/handler/thin.rb:16:in `run'
rack (1.5.5) lib/rack/server.rb:264:in `start'
railties (4.1.4) lib/rails/commands/server.rb:69:in `start'
railties (4.1.4) lib/rails/commands/commands_tasks.rb:81:in `block in server'
railties (4.1.4) lib/rails/commands/commands_tasks.rb:76:in `server'
railties (4.1.4) lib/rails/commands/commands_tasks.rb:40:in `run_command!'
railties (4.1.4) lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:4:in `<main>'
I have a Rails app that runs in a Docker container which is assigned an ip 172.17.0.3. Incoming requests to the host machine 51.x.x.x are forwarded to the rails app in 172.17.0.3. More specifically, this was done as such:
docker run -p 8080:8080 rails_app
However, Rails app throws Can't verify CSRF token authenticity error when a user tries to access some of the pages. My suspicion is that Rails thinks the incoming request is an attack, since the ip of the destination doesn't match the ip of the Rails app - i.e. user requests are directed to the host machine 51.x.x.x, whereas Rails actual location is at 172.17.0.3
Is there any way for me to tell Rails that these requests are legit? As an additional info, I use devise for authentication, and unicorn as the server.
Some of you might be tempted to suggest changing protect_from_forgery with: :exception to :null_session, but the application works just fine when not placed behind a proxy. Besides, some of the logic will not work when I changed that part since I think the setting messes with the way a user session is handled.
This is the layout of my network:
(user from public network) ----> (proxy) ----> (rails app on a private network)
(202.x.x.x) (51.x.x.x) (172.x.x.x)
EDIT:
The app is in development settings. Here's the error I got in log/development.log files.
Started POST "/register" for 202.x.x.x at 2014-11-18 02:27:11 +0000
Processing by UsersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"aBG3nIAKK1ALMJ1DDYFlMkmqISMBMZc3iLmaeD2byG8=", "user"=>{"email"=>"email#gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}
Can't verify CSRF token authenticity
Completed 422 Unprocessable Entity in 2ms
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
actionpack (4.1.4) lib/action_controller/metal/request_forgery_protection.rb:176:in `handle_unverified_request'
actionpack (4.1.4) lib/action_controller/metal/request_forgery_protection.rb:202:in `handle_unverified_request'
devise (3.4.0) lib/devise/controllers/helpers.rb:251:in `handle_unverified_request'
actionpack (4.1.4) lib/action_controller/metal/request_forgery_protection.rb:197:in `verify_authenticity_token'
activesupport (4.1.4) lib/active_support/callbacks.rb:424:in `block in make_lambda'
activesupport (4.1.4) lib/active_support/callbacks.rb:160:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:160:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.4) lib/active_support/callbacks.rb:149:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.4) lib/active_support/callbacks.rb:149:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.4) lib/active_support/callbacks.rb:86:in `run_callbacks'
actionpack (4.1.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.1.4) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.4) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.1.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.1.4) lib/abstract_controller/base.rb:136:in `process'
actionview (4.1.4) lib/action_view/rendering.rb:30:in `process'
actionpack (4.1.4) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.1.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.4) lib/action_controller/metal.rb:232:in `block in action'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:82:in `call'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.1.4) lib/action_dispatch/routing/mapper.rb:45:in `call'
actionpack (4.1.4) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.1.4) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.4) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:678:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.4) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.4) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.4) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/static.rb:64:in `call'
rack-cors (0.2.9) lib/rack/cors.rb:54:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.4) lib/rails/engine.rb:514:in `call'
railties (4.1.4) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lint.rb:49:in `_call'
rack (1.5.2) lib/rack/lint.rb:37:in `call'
rack (1.5.2) lib/rack/showexceptions.rb:24:in `call'
rack (1.5.2) lib/rack/commonlogger.rb:33:in `call'
sinatra (1.4.5) lib/sinatra/base.rb:217:in `call'
rack (1.5.2) lib/rack/chunked.rb:43:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
unicorn (4.8.3) lib/unicorn/http_server.rb:576:in `process_client'
unicorn (4.8.3) lib/unicorn/http_server.rb:670:in `worker_loop'
unicorn (4.8.3) lib/unicorn/http_server.rb:525:in `spawn_missing_workers'
unicorn (4.8.3) lib/unicorn/http_server.rb:140:in `start'
unicorn (4.8.3) bin/unicorn:126:in `<top (required)>'
From a cursory reading of the 'protect_from_forgery method', we find the following:
def protect_from_forgery(options = {})
self.forgery_protection_strategy = protection_method_class(options[:with] || :null_session)
self.request_forgery_protection_token ||= :authenticity_token
prepend_before_action :verify_authenticity_token, options
append_after_action :verify_same_origin_request
end
Which has a before action callback called 'verify_authenticity_token'. If we look at its source we find the following:
def verify_authenticity_token
mark_for_same_origin_verification!
if !verified_request?
logger.warn "Can't verify CSRF token authenticity" if logger
handle_unverified_request
end
end
From there we note that it calls 'verified_request?'.
def verified_request?
!protect_against_forgery? || request.get? || request.head? ||
form_authenticity_token == params[request_forgery_protection_token] ||
form_authenticity_token == request.headers['X-CSRF-Token']
end
Given the nature of the raised exception, I would think that one or more of those conditions are not being met. I don't think that it has anything to do with the IP addressing.
If your rails app is speaking over non-SSL to your proxy, there could be an issue where your ActiveRecord::SessionStore is throwing a fit because of that scenario.
Our fix was to make the session store insecure:
OurApplication::Application.config.session_store :active_record_store, secure: false
Edit: Still no fix yet... We're probably going to have to make the SSL terminate at the apps as opposed to the proxy over this.
So for us, the issue had nothing to do with SSL in the end. We had a javascript call being executed on the first page load that was trying to perform a handshake against a backend service (via a POST), but we hadn't properly configured our HAProxy to route calls to that service, so instead the POST was hitting Rails. Even though Rails returned a 404 for the route, it also reset the session because of the missing CSRF token in the request. Fixing HAProxy's routing fixed the issue.
Our scenario likely has almost nothing to do with yours, and in Rails 4, they made the default behavior of protect_from_forgery be to raise an exception instead of resetting the session. Oh, and we did also ultimately need to set the session store to insecure:
OurApplication::Application.config.session_store :active_record_store, secure: false
I'm having a problem updating params after I switched to strong params. I'm getting a wrong number of arguments error, here's the trace:
Started PATCH "/profiles/rails/about_me" for 127.0.0.1 at 2014-09-23 12:14:19 -0700
Processing by UsersController#about_me as
Parameters: {"utf8"=>"✓", "user"=>{"about_me"=>"testt"}, "commit"=>"Update Biography", "id"=>"rails"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."deleted" = 'f' AND "users"."id" = 10 ORDER BY "users"."id" ASC LIMIT 1
(0.2ms) SELECT COUNT(*) FROM "terms" INNER JOIN "terms_users" ON "terms"."id" = "terms_users"."term_id" WHERE "terms_users"."user_id" = $1 AND "terms"."name" = 'application' [["user_id", 10]]
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."deleted" = 'f' AND "users"."slug" = 'rails' ORDER BY "users"."id" ASC LIMIT 1
Completed 500 Internal Server Error in 14ms
127.0.0.1 POST /profiles/rails/about_me 500 Internal Server Error UsersController#about_me JS 13.8 (DB 0.0, View 0.0) {"utf8"=>"✓", "user"=>{"about_me"=>"testt"}, "commit"=>"Update Biography", "id"=>"rails"} {}
** [Airbrake] Notice was not sent due to configuration:
Environment Monitored? false
API key set? true
ArgumentError - wrong number of arguments (2 for 1):
app/models/user.rb:347:in `update_profile'
app/controllers/users_controller.rb:173:in `shared_update'
app/controllers/users_controller.rb:72:in `about_me'
actionpack (4.1.6) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.6) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.6) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.1.6) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.6) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.6) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.6) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.6) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.6) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional'
activesupport (4.1.6) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.6) lib/active_support/callbacks.rb:229:in `block in halting'
activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.6) lib/active_support/callbacks.rb:166:in `block in halting'
activesupport (4.1.6) lib/active_support/callbacks.rb:86:in `run_callbacks'
actionpack (4.1.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.1.6) lib/action_controller/metal/rescue.rb:29:in `process_action'
config/initializers/log_formatter.rb:22:in `block (2 levels) in <top (required)>'
activesupport (4.1.6) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.1.6) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.6) lib/active_support/notifications.rb:159:in `instrument'
config/initializers/log_formatter.rb:21:in `block in <top (required)>'
actionpack (4.1.6) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.1.6) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.1.6) lib/abstract_controller/base.rb:136:in `process'
actionview (4.1.6) lib/action_view/rendering.rb:30:in `process'
rack-mini-profiler (0.9.2) lib/mini_profiler/profiling_methods.rb:108:in `block in profile_method'
actionpack (4.1.6) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.1.6) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.6) lib/action_controller/metal.rb:232:in `block in action'
actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.1.6) lib/action_dispatch/journey/router.rb:73:in `block in call'
actionpack (4.1.6) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.6) lib/action_dispatch/routing/route_set.rb:678:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
apipie-rails (0.2.6) lib/apipie/static_dispatcher.rb:65:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
bullet (4.13.2) lib/bullet/rack.rb:12:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
apipie-rails (0.2.6) lib/apipie/extractor/recorder.rb:97:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/rack/error_collector.rb:50:in `traced_call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/rack/agent_hooks.rb:26:in `traced_call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/rack/browser_monitoring.rb:23:in `traced_call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/rack/developer_mode.rb:48:in `traced_call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:55:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
remotipart (1.2.1) lib/remotipart/middleware.rb:27:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/flash.rb:254:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/cookies.rb:560:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
activerecord (4.1.6) lib/active_record/query_cache.rb:36:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.6) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/reloader.rb:73:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
airbrake (4.1.0) lib/airbrake/rails/middleware.rb:13:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
better_errors (2.0.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.0.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.0.0) lib/better_errors/middleware.rb:57:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
activesupport (4.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
heroku-deflater (0.5.3) lib/heroku-deflater/skip_binary.rb:19:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/deflater.rb:25:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
heroku-deflater (0.5.3) lib/heroku-deflater/serve_zipped_assets.rb:50:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
airbrake (4.1.0) lib/airbrake/user_informer.rb:16:in `_call'
airbrake (4.1.0) lib/airbrake/user_informer.rb:12:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack-mini-profiler (0.9.2) lib/mini_profiler/profiler.rb:300:in `call'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
railties (4.1.6) lib/rails/engine.rb:514:in `call'
railties (4.1.6) lib/rails/application.rb:144:in `call'
railties (4.1.6) lib/rails/railtie.rb:194:in `method_missing'
newrelic_rpm (3.9.4.245) lib/new_relic/agent/instrumentation/middleware_tracing.rb:57:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
thin (1.6.2) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.6.2) lib/thin/connection.rb:84:in `pre_process'
thin (1.6.2) lib/thin/connection.rb:53:in `process'
thin (1.6.2) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
thin (1.6.2) lib/thin/backends/base.rb:73:in `start'
thin (1.6.2) lib/thin/server.rb:162:in `start'
rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
rack (1.5.2) lib/rack/server.rb:264:in `start'
railties (4.1.6) lib/rails/commands/server.rb:69:in `start'
railties (4.1.6) lib/rails/commands/commands_tasks.rb:81:in `block in server'
railties (4.1.6) lib/rails/commands/commands_tasks.rb:76:in `server'
railties (4.1.6) lib/rails/commands/commands_tasks.rb:40:in `run_command!'
railties (4.1.6) lib/rails/commands.rb:17:in `<top (required)>'
script/rails:6:in `<main>'
User.rb:347:update_profile:
def update_profile(attributes, options = {})
return false if attributes.nil?
previous_avatar = !has_default_avatar?
assign_attributes(attributes, options)
if valid?
if about_me_changed? || attributes[:avatar]
uploaded_avatar = (attributes[:avatar].nil?)? false : true
BadgesStrategies::Profile.assign_based_on(self, about_me: [about_me_was, about_me], avatar: [previous_avatar, uploaded_avatar])
end
end
save
end
UsersController:shared_update:
def shared_update
params[:user].delete(:password) if params[:user] && params[:user][:password].blank?
params[:user].delete(:password_confirmation) if params[:user] && params[:user][:password].blank? and params[:user][:password_confirmation].blank?
email_changed = params[:user] && params[:user][:email] && #user.email != params[:user][:email]
if #user.update_profile(user_params)
sign_in #user, bypass: true
if email_changed
if #user.pending_reconfirmation?
flash[:notice] = "Success! Please check '#{params[:user][:email]}' for instructions to complete the update process."
else
flash[:notice] = "Successfully changed to '#{params[:user][:email]}'"
end
else
flash[:notice] = "Your profile is successfully updated"
end
else
flash[:alert] = (params[:user].nil? )? "ERROR: No user information sent for update" : "ERROR: #{#user.errors.full_messages.to_sentence}"
end
end
UsersController:about_me:
def about_me
shared_update
render partial: 'users/about_me', locals: { user: #user }
end
Could somebody look through this and tell me what exactly is going wrong? Is it a syntax error in Rails 4?
If user.rb line 347 is this line:
assign_attributes(attributes, options)
Then there's your problem. ActiveRecord#assign_attributes appears to only take one argument in Rails 4.
See docs here
Rails 3's API for the method did allow an options hash. See docs here.
In rails 3, the options seems to have handled access control allowing to configure who was able to do mass assignment. In rails 4 with strong params, that responsibility has shifted to the param hash itself.
The rails 4 docs state:
If the passed hash responds to permitted? method and the return value of this method is false an ActiveModel::ForbiddenAttributesError exception is raised.
In conclusion, when you get a message telling you that you aren't passing the right arguments to a method, the first thing you do should be to look up that method in the documentation and see how you are supposed to use it.
I had no idea when I read this question what the answer was. I just found the method that you were passing two arguments into you your code, and then looked up the docs and the answer was pretty clear.