Techioz Blog

Sidekiq/Redis 接続がコード WSAENOPROTOOPT で失敗する

概要

Sidekiq に依存する Ruby on Rails アプリを構築しています。このアプリは Windows サーバー VM 上で実行され、Redis は Debian 11 VM 上で実行されます。

Sidekiq サーバーを起動すると、このエラー メッセージが表示されます。

2024-05-17T14:54:24.857Z pid=27468 tid=jrw INFO: Booted Rails 7.1.3.2 application in development environment
Signal TTIN not supported
Signal TSTP not supported
2024-05-17T14:54:24.862Z pid=27468 tid=jrw INFO: Running in ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [x64-mingw-ucrt]
2024-05-17T14:54:24.863Z pid=27468 tid=jrw INFO: See LICENSE and the LGPL-3.0 for licensing details.
2024-05-17T14:54:24.865Z pid=27468 tid=jrw INFO: Upgrade to Sidekiq Pro for more features and support: https://sidekiq.org
2024-05-17T14:54:24.866Z pid=27468 tid=jrw INFO: Sidekiq 7.2.2 connecting to Redis with options {:size=>10, :pool_name=>"internal", :url=>"redis://192.168.1.79:6379/0"}
Une option ou un niveau inconnu, non valide ou non pris en charge a ÚtÚ spÚcifiÚ dans un appel getsockopt ou setsockopt. - setsockopt(2) (redis://192.168.1.79:6379)
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client/ruby_connection.rb:174:in `setsockopt'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client/ruby_connection.rb:174:in `enable_socket_keep_alive'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client/ruby_connection.rb:125:in `connect'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client/ruby_connection.rb:51:in `initialize'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client.rb:746:in `new'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client.rb:746:in `block in connect'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client/middlewares.rb:12:in `connect'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client.rb:745:in `connect'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client.rb:732:in `raw_connection'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client.rb:697:in `ensure_connected'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client.rb:277:in `call'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/redis-client-0.21.1/lib/redis_client/decorator.rb:26:in `call'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/sidekiq-7.2.2/lib/sidekiq/config.rb:144:in `block in redis_info'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/sidekiq-7.2.2/lib/sidekiq/config.rb:163:in `block in redis'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/connection_pool-2.4.1/lib/connection_pool.rb:110:in `block (2 levels) in with'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/connection_pool-2.4.1/lib/connection_pool.rb:109:in `handle_interrupt'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/connection_pool-2.4.1/lib/connection_pool.rb:109:in `block in with'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/connection_pool-2.4.1/lib/connection_pool.rb:106:in `handle_interrupt'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/connection_pool-2.4.1/lib/connection_pool.rb:106:in `with'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/sidekiq-7.2.2/lib/sidekiq/config.rb:160:in `redis'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/sidekiq-7.2.2/lib/sidekiq/config.rb:143:in `redis_info'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/sidekiq-7.2.2/lib/sidekiq/cli.rb:75:in `run'
D:/Projects/vendor/bundle/ruby/3.2.0/gems/sidekiq-7.2.2/bin/sidekiq:31:in `<top (required)>'
D:/Projects/vendor/bundle/ruby/3.2.0/bin/sidekiq:25:in `load'
D:/Projects/vendor/bundle/ruby/3.2.0/bin/sidekiq:25:in `<main>'

エラー コード WSAENOPROTOOPT (10042) に関連するこのメッセージは、WinSock API の setsockopt 関数の “optname” または “level” 引数のエラーを示しているようです。 ただし、Sidekiq に関して同様の問題を抱えている人は見つかっていないため、問題は私側から発生しているのではないかと考えています。しかし、私の conf ファイルはほとんど空です (問題がどこにあるのかわかりません)。

sidekiq.yaml

---
:concurrency: 10
test:
  :concurrency: 20
development:
  :concurrency: 10
:queues:
  -default
  -compute

ドキュメントのガイドに従って、REDIS_URL の環境変数を作成しました。

解決策

ここでネットワークに問題があるようです