2

我看到一个与 Active Record 会话存储相关的不寻常的打嗝,它间歇性地发生(并且我无法在本地重现):

NoMethodError:nil:NilClass 的未定义方法“删除”

导轨:3.2.21

我正在使用 active_record_store 并且堆栈跟踪没有通过我的应用程序。有趣的是,堆栈跟踪通过 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 和数据字段中)——我无法在开发中完全重现这一点。

• 这发生在我的应用程序中不同位置的不同用户身上(发生率为千分之一)。

• 同一个用户似乎连续发生了几次(如果他们加载超过 1 个页面并出现相同的会话问题,这很有意义)

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

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

这里有什么补救建议吗?

4

1 回答 1

0

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

于 2015-03-20T16:57:21.197 回答