Help us understand the problem. What is going on with this article?

Sidekiqのダッシュボードでエラーが出ていたので対応した

最近Sidekiqのダッシュボード(Sidekiq::Web)がエラーで表示されない現象が発生したので、調査結果と対応をまとめておきます。同じ現象に困っている人の参考になれば:pray:

バージョン

ライブラリ バージョン
rails 5.2.2.1
sidekiq 5.2.5
redis 4.1.0
rack 2.0.8

エラー内容

マウントしたパスにアクセスすると、以下のRuntime Errorが出ます。どうやらRackのセッション周りでエラーになっているようです。

エラーが出たRailsアプリケーションではセッション管理にRedisを使っているのですが、試しに別の形式に変えるとエラーが消えました。

RuntimeError (Most recent call first)
Hide 33 non-project frames
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/lib/rack/session/abstract/id.rb line 31 in to_s
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/redis-session-store-0.11.0/lib/redis-session-store.rb line 87 in prefixed
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/redis-session-store-0.11.0/lib/redis-session-store.rb line 123 in set_session
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/lib/rack/session/abstract/id.rb line 381 in commit_session
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/lib/rack/session/abstract/id.rb line 261 in context
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/lib/rack/session/abstract/id.rb line 253 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/cookies.rb line 670 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/callbacks.rb line 28 in block in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/callbacks.rb line 98 in run_callbacks
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/callbacks.rb line 26 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rollbar-2.19.2/lib/rollbar/middleware/rails/rollbar.rb line 24 in block in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rollbar-2.19.2/lib/rollbar.rb line 146 in scoped
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rollbar-2.19.2/lib/rollbar/middleware/rails/rollbar.rb line 22 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/debug_exceptions.rb line 61 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rollbar-2.19.2/lib/rollbar/middleware/rails/show_exceptions.rb line 22 in call_with_rollbar
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/show_exceptions.rb line 33 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/rack/logger.rb line 38 in call_app
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/rack/logger.rb line 28 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/remote_ip.rb line 81 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/request_store-1.4.1/lib/request_store/middleware.rb line 19 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/request_id.rb line 27 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/lib/rack/method_override.rb line 22 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/lib/rack/runtime.rb line 22 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb line 29 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/executor.rb line 14 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/rack-2.0.8/lib/rack/sendfile.rb line 111 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/railties-5.2.2.1/lib/rails/engine.rb line 524 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/stackprof-0.2.12/lib/stackprof/middleware.rb line 22 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.2/lib/puma/configuration.rb line 227 in call
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.2/lib/puma/server.rb line 674 in handle_request
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.2/lib/puma/server.rb line 476 in process_client
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.2/lib/puma/server.rb line 334 in block in run
File /var/www/app/vendor/bundle/ruby/2.6.0/gems/puma-3.12.2/lib/puma/thread_pool.rb line 135 in block in spawn_thread

Sidekiqのセッションを無効にしてみる

セッション周りっぽいので、とりあえずSidekiqのセッションを無効にしてみます。

diff --git a/config/routes/admin.rb b/config/routes/admin.rb
index 218cdc9960..a4a40e4195 100644
--- a/config/routes/admin.rb
+++ b/config/routes/admin.rb
@@ -1,7 +1,7 @@
 # frozen_string_literal: true

 require 'sidekiq/web'
-Sidekiq::Web.set :session_secret, Rails.application.secrets[:secret_key_base]
+Sidekiq::Web.set :sessions, false # 上の一行をこちらに書き換えてセッションを無効化

 Rails.application.routes.draw do
   ActiveAdmin.routes(self)

無事表示されました。引き続き調べます。

rack/rack#1432

調べていくとRackに関係のありそうなIssueが上がっているのを見つけました。
https://github.com/rack/rack/issues/1432

どうやら2.0.8のセキュリティフィックスで仕様が変わり不具合が起こるようになったとのこと。以下のコミットで解消されており、修正は2.0.9に含まれているようです。
https://github.com/rack/rack/pull/1462

ということで、Rackのバージョンを上げれば良さそうなので上げてみます。

$ bundle update rack

バージョンが2.0.8から2.0.9に上がりエラーが解消されました。やったね:clap:

campfirejp
国内最大の流通を誇るクラウドファンディングサービス「CAMPFIRE」の企画・開発・運営を行うスタートアップです
https://camp-fire.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした