NoMethodError:nil的未定义方法`delete':NilClass; Rails 3.2.21,Spree 2.0.13.beta;使用Active Record Session存储

时间:2015-01-17 20:45:20

标签: ruby-on-rails activerecord rails-activerecord spree session-store

我发现与Active Record Session存储有关的异常打嗝是间歇性发生的(我无法在本地重现):

NoMethodError:nil的未定义方法`delete':NilClass

Rails:3.2.21

我正在使用active_record_store并且堆栈跟踪不会通过我的应用程序。有趣的是,堆栈跟踪传递了thruogh active_record / session_store.rb代码 完整的堆栈跟踪:

y/2.0.0/gems/activerecord-3.2.21/lib/active_record/attribute_methods/write.rb:28 :in `write_attribute`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/attribute_methods/dirty.rb:67 :in `write_attribute`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/attribute_methods.rb:31 :in `[]=`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/associations/collection_association.rb:413 :in `block (2 levels) in merge_target_lists`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/associations/collection_association.rb:412 :in `each`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/associations/collection_association.rb:412 :in `block in merge_target_lists`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/associations/collection_association.rb:404 :in `map!`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/associations/collection_association.rb:404 :in `merge_target_lists`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/associations/collection_association.rb:335 :in `load_target`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/associations/collection_proxy.rb:44 :in `load_target`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/associations/collection_proxy.rb:73 :in `respond_to?`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/session_store.rb:56 :in `dump`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/session_store.rb:56 :in `marshal`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/session_store.rb:150 :in `marshal_data!`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:407 :in `_run__823684787928912900__save__1569062307686968059__callbacks`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:405 :in `__run_callback`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:385 :in `_run_save_callbacks`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:81 :in `run_callbacks`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/callbacks.rb:264 :in `create_or_update`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/persistence.rb:84 :in `save`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/validations.rb:50 :in `save`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/attribute_methods/dirty.rb:22 :in `save`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/transactions.rb:259 :in `block (2 levels) in save`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/transactions.rb:313 :in `block in with_transaction_returning_status`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract/database_statements.rb:192 :in `transaction`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/transactions.rb:208 :in `transaction`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/method_tracer.rb:343 :in `block in transaction_with_trace_ActiveRecord_self_name_transaction`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/method_tracer_helpers.rb:82 :in `trace_execution_scoped`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/method_tracer.rb:341 :in `transaction_with_trace_ActiveRecord_self_name_transaction`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/transactions.rb:311 :in `with_transaction_returning_status`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/transactions.rb:259 :in `block in save`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/transactions.rb:270 :in `rollback_active_record_state!`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/transactions.rb:258 :in `save`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/session_store.rb:323 :in `block in set_session`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/benchmarkable.rb:50 :in `silence`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/session_store.rb:320 :in `set_session`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:327 :in `commit_session`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:211 :in `context`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.21/lib/action_dispatch/middleware/cookies.rb:341 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/query_cache.rb:64 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract/connection_pool.rb:479 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.21/lib/action_dispatch/middleware/callbacks.rb:28 :in `block in call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:405 :in `_run__2585645259320754309__call__1569062307686968059__callbacks`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:405 :in `__run_callback`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:385 :in `_run_call_callbacks`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/callbacks.rb:81 :in `run_callbacks`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.21/lib/action_dispatch/middleware/callbacks.rb:27 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.21/lib/action_dispatch/middleware/remote_ip.rb:31 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.21/lib/action_dispatch/middleware/debug_exceptions.rb:16 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.21/lib/action_dispatch/middleware/show_exceptions.rb:56 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/railties-3.2.21/lib/rails/rack/logger.rb:32 :in `call_app`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/railties-3.2.21/lib/rails/rack/logger.rb:16 :in `block in call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/tagged_logging.rb:22 :in `tagged`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/railties-3.2.21/lib/rails/rack/logger.rb:16 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.21/lib/action_dispatch/middleware/request_id.rb:22 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/methodoverride.rb:21 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/runtime.rb:17 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/activesupport-3.2.21/lib/active_support/cache/strategy/local_cache.rb:72 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/lock.rb:15 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.21/lib/action_dispatch/middleware/static.rb:83 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:136 :in `forward`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:245 :in `fetch`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:185 :in `lookup`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:66 :in `call!`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-cache-1.2/lib/rack/cache/context.rb:51 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/rack-timeout-0.1.0/lib/rack/timeout.rb:104 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/railties-3.2.21/lib/rails/engine.rb:484 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/railties-3.2.21/lib/rails/application.rb:231 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/railties-3.2.21/lib/rails/railtie/configurable.rb:30 :in `method_missing`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/newrelic_rpm-3.9.8.273/lib/new_relic/agent/instrumentation/middleware_tracing.rb:57 :in `call`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:576 :in `process_client`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:670 :in `worker_loop`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525 :in `spawn_missing_workers`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:140 :in `start`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/gems/unicorn-4.8.3/bin/unicorn:126 :in `<top (required)>`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/bin/unicorn:23 :in `load`
[PROJECT_ROOT]/vendor/bundle/ruby/2.0.0/bin/unicorn:23 :in `<main>

一些观察结果:

•我尝试以此用户身份登录,并且还按记录ID劫持用户的会话(将假会话ID移动到症状所在的会话的sessin id&amp; data字段中) - 我无法重现此在开发中完全。

•这发生在我的应用程序中不同位置的不同用户上(出现数千次点击中的1次)。

•看起来它连续几次发生在同一个用户身上(如果加载的页数超过1页且会话问题相同,则有意义)

•检查发生问题的会话的会话表我发现这些记录的“数据”字段非常大,例如:https://gist.github.com/jasonfb/109af1b7f1595c115c85

所有包含错误会话的记录都包含大量数据,而我的其他会话记录看起来只有几行数据。

有任何补救建议吗?

1 个答案:

答案 0 :(得分:0)

通过升级到Rails 4来解决这个问题。我从未在Rails 3.2下找到解决方案,但我确实将问题隔离到了活动记录的深处。