如何修复 Heroku 上的 ActionDispatch::Cookies::CookieOverflow 错误?

Posted

技术标签:

【中文标题】如何修复 Heroku 上的 ActionDispatch::Cookies::CookieOverflow 错误?【英文标题】:How to fix ActionDispatch::Cookies::CookieOverflow error on heroku? 【发布时间】:2015-02-21 05:49:06 【问题描述】:

我经常在我的 rails 应用程序中的 heroku 上收到 ActionDispatch::Cookies::CookieOverflow 错误。 我认为在会话中转储未使用的信息,例如

env["airbrake.error_id"] = notify_airbrake(e)

可能有问题。

我已将许多字符串转储到会话中,也许这可能是问题所在。 我读了一些帖子,这表明这也可能是因为activeadmin。 最后我想按照here的建议创建一个会话表@

我不知道解决此问题的最佳方法是什么? 请提出所有可能的解决方案。

我的 config/initializers/session_store.rb 中的代码

Demo::Application.config.session_store :cookie_store, key: '_demo_appplication', :domain => :all

通过airbrake,我得到了这个错误堆栈跟踪

[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/cookies.rb:471:in []=
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/session/cookie_store.rb:110:in set_cookie
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:350:in commit_session
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:226:in context
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/cookies.rb:560:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/query_cache.rb:36:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/callbacks.rb:29:in block in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:82:in run_callbacks
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/callbacks.rb:27:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/remote_ip.rb:76:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/debug_exceptions.rb:17:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/rack/logger.rb:38:in call_app
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/rack/logger.rb:20:in block in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/tagged_logging.rb:68:in block in tagged
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/tagged_logging.rb:26:in tagged
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/tagged_logging.rb:68:in tagged
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/rack/logger.rb:20:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/request_id.rb:21:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.1/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/actionpack-4.1.1/lib/action_dispatch/middleware/static.rb:64:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/heroku-deflater-0.5.3/lib/heroku-deflater/skip_binary.rb:19:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/deflater.rb:25:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/heroku-deflater-0.5.3/lib/heroku-deflater/serve_zipped_assets.rb:50:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/dragonfly-1.0.5/lib/dragonfly/cookie_monster.rb:9:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/font_assets-0.1.11/lib/font_assets/middleware.rb:29:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/engine.rb:514:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/application.rb:144:in call
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/railtie.rb:194:in public_send
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/railties-4.1.1/lib/rails/railtie.rb:194:in method_missing
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:576:in process_client
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:670:in worker_loop
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525:in spawn_missing_workers
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:140:in start
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in <top (required)>
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in load
[PROJECT_ROOT]/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in <main>

【问题讨论】:

检查是否在哈希中使用过多 【参考方案1】:

Rails cookie 限制为 4KB。请注意,会话也存储在默认配置中的 cookie 中。见:http://guides.rubyonrails.org/security.html#session-storage

您唯一能做的就是:不要在 cookie 中存储大对象。将它们存储在数据库中,然后仅将对象的id 存储在cookie中。

您可能也对这个答案感兴趣:https://***.com/a/4604212/2483313

【讨论】:

以上是关于如何修复 Heroku 上的 ActionDispatch::Cookies::CookieOverflow 错误?的主要内容,如果未能解决你的问题,请参考以下文章

推送到 Heroku 时如何修复“错误:src refspec master 不匹配任何”错误?

当我在终端上输入“heroku logs --tail”时如何修复以下错误?这是啥意思?

如何修复 SQLSTATE [42704]:未定义对象:7 错误:数据类型 json 在heroku 托管中没有访问方法“btree”的默认运算符类

如何在 Windows 10 上修复 Heroku CLI 安装程序错误“此应用已被阻止以保护您”?

多个帐户heroku键混淆

如何让我在 Heroku 上的 Laravel 项目使用 Heroku Postgres?