redis / redis-rb

A Ruby client library for Redis
MIT License
3.96k stars 1.03k forks source link

initialize': no implicit conversion of String into Integer (TypeError) #1277

Closed yuvalIndie closed 4 months ago

yuvalIndie commented 4 months ago

Hey there ! trying to run websockets using action_cable sidekiq and redis (heroku redis addon). on staging env that has same redis machine im able to run everything smoothly but on production upon trying to connect to websocket: wss://XXXXXX.herokuapp.com/cable i get the next error: /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:22:ininitialize': no implicit conversion of String into Integer (TypeError)`

full trace from heroku logs:

#<Thread:0x000055dbe22f8230 /app/vendor/bundle/ruby/2.7.0/gems/actioncable-6.1.7.7/lib/action_cable/subscription_adapter/redis.rb:150 run> terminated with exception (report_on_exception is true):
2024-05-12T11:29:43.242239+00:00 app[web.1]: /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:22:in `initialize': no implicit conversion of String into Integer (TypeError)
2024-05-12T11:29:43.242269+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:22:in `initialize'
2024-05-12T11:29:43.242269+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:254:in `new'
2024-05-12T11:29:43.242271+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:254:in `connect'
2024-05-12T11:29:43.242271+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:306:in `connect'
2024-05-12T11:29:43.242273+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:385:in `establish_connection'
2024-05-12T11:29:43.242281+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:115:in `block in connect'
2024-05-12T11:29:43.242281+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:344:in `with_reconnect'
2024-05-12T11:29:43.242281+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:114:in `connect'
2024-05-12T11:29:43.242282+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:325:in `with_socket_timeout'
2024-05-12T11:29:43.242283+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:174:in `call_loop'
2024-05-12T11:29:43.242283+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/subscribe.rb:44:in `subscription'
2024-05-12T11:29:43.242287+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/subscribe.rb:14:in `subscribe'
2024-05-12T11:29:43.242287+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:288:in `_subscription'
2024-05-12T11:29:43.242289+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/commands/pubsub.rb:20:in `block in subscribe'
2024-05-12T11:29:43.242289+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `block in synchronize'
2024-05-12T11:29:43.242298+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `synchronize'
2024-05-12T11:29:43.242298+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `synchronize'
2024-05-12T11:29:43.242298+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/commands/pubsub.rb:19:in `subscribe'
2024-05-12T11:29:43.242299+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/actioncable-6.1.7.7/lib/action_cable/subscription_adapter/redis.rb:83:in `block in listen'
2024-05-12T11:29:43.242300+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:344:in `with_reconnect'
2024-05-12T11:29:43.242300+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:95:in `block in with_reconnect'
2024-05-12T11:29:43.242303+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `block in synchronize'
2024-05-12T11:29:43.242304+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `synchronize'
2024-05-12T11:29:43.242305+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `synchronize'
2024-05-12T11:29:43.242308+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:94:in `with_reconnect'
2024-05-12T11:29:43.242309+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:101:in `without_reconnect'
2024-05-12T11:29:43.242310+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/actioncable-6.1.7.7/lib/action_cable/subscription_adapter/redis.rb:80:in `listen'
2024-05-12T11:29:43.242318+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/actioncable-6.1.7.7/lib/action_cable/subscription_adapter/redis.rb:154:in `block in ensure_listener_running'
2024-05-12T11:29:43.285150+00:00 app[web.1]: /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:22:in `initialize': no implicit conversion of String into Integer (TypeError)
2024-05-12T11:29:43.285154+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:22:in `initialize'
2024-05-12T11:29:43.285154+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:254:in `new'
2024-05-12T11:29:43.285155+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:254:in `connect'
2024-05-12T11:29:43.285155+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/connection/ruby.rb:306:in `connect'
2024-05-12T11:29:43.285155+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:385:in `establish_connection'
2024-05-12T11:29:43.285156+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:115:in `block in connect'
2024-05-12T11:29:43.285156+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:344:in `with_reconnect'
2024-05-12T11:29:43.285156+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:114:in `connect'
2024-05-12T11:29:43.285156+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:325:in `with_socket_timeout'
2024-05-12T11:29:43.285158+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:174:in `call_loop'
2024-05-12T11:29:43.285158+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/subscribe.rb:44:in `subscription'
2024-05-12T11:29:43.285163+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/subscribe.rb:14:in `subscribe'
2024-05-12T11:29:43.285164+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:288:in `_subscription'
2024-05-12T11:29:43.285168+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/commands/pubsub.rb:20:in `block in subscribe'
2024-05-12T11:29:43.285169+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `block in synchronize'
2024-05-12T11:29:43.285179+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `synchronize'
2024-05-12T11:29:43.285180+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `synchronize'
2024-05-12T11:29:43.285184+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/commands/pubsub.rb:19:in `subscribe'
2024-05-12T11:29:43.285189+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/actioncable-6.1.7.7/lib/action_cable/subscription_adapter/redis.rb:83:in `block in listen'
2024-05-12T11:29:43.285189+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis/client.rb:344:in `with_reconnect'
2024-05-12T11:29:43.285199+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:95:in `block in with_reconnect'
2024-05-12T11:29:43.285200+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `block in synchronize'
2024-05-12T11:29:43.285209+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `synchronize'
2024-05-12T11:29:43.285209+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:265:in `synchronize'
2024-05-12T11:29:43.285213+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:94:in `with_reconnect'
2024-05-12T11:29:43.285222+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/redis-4.8.1/lib/redis.rb:101:in `without_reconnect'
2024-05-12T11:29:43.285223+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/actioncable-6.1.7.7/lib/action_cable/subscription_adapter/redis.rb:80:in `listen'
2024-05-12T11:29:43.285232+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.7.0/gems/actioncable-6.1.7.7/lib/action_cable/subscription_adapter/redis.rb:154:in `block in ensure_listener_running'
2024-05-12T11:29:43.380994+00:00 app[web.1]: [2] - Worker 0 (PID: 28) booted in 0.0s, phase: 0
2024-05-12T11:29:43.000000+00:00 app[redis-asymmetrical-47170]: Error accepting a client connection: (null)

cable.rb:

development:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>

test:
  adapter: redis
  url: <%= ENV["REDIS_URL"] %>
  ssl_params:
    verify_mode: <%= OpenSSL::SSL::VERIFY_NONE %>

staging:
  adapter: redis
  url: <%= ENV["REDIS_URL"] %>
  ssl_params:
    verify_mode: <%= OpenSSL::SSL::VERIFY_NONE %>

production:
  adapter: redis
  url: <%= ENV["REDIS_URL"] %>
  channel_prefix: bw_backend_production
  ssl_params:
    verify_mode: OpenSSL::SSL::VERIFY_NONE # For debugging SSL issues only

sidekiq.rb initilazer:

# require 'logtail'
ssl_params = {
  verify_mode: OpenSSL::SSL::VERIFY_NONE,
}

Sidekiq.configure_server do |config|
  config.redis = { url: ENV.fetch('REDIS_URL', 'redis://localhost:6379/1'),  ssl_params: ssl_params }
  config.logger = Sidekiq::Logger.new($stdout)
  config.logger.level = Logger::INFO
end

Sidekiq.configure_client do |config|
  config.redis = { url: ENV.fetch('REDIS_URL', 'redis://localhost:6379/1'), ssl_params: ssl_params }
end

redis.rb initializer

equire 'uri'
require 'redis'

redis_uri = URI.parse(ENV['REDIS_URL'] || 'redis://localhost:6379/1')

redis_options = {
  host: redis_uri.host,
  port: redis_uri.port.to_i,  # Convert port to integer
  password: redis_uri.password,
  ssl: redis_uri.scheme == 'rediss',  # Enable SSL if scheme is 'rediss'
  ssl_params: {
    verify_mode: OpenSSL::SSL::VERIFY_NONE  # Match ssl_cert_reqs=CERT_NONE
  }
}

redis_options[:port] = redis_uri.port.to_i if redis_uri.port

# Initialize Redis client
Redis.new(redis_options)

configuration added:

  config.action_cable.url = 'wss://XXXX.herokuapp.com/cable'
  config.action_cable.allowed_request_origins = [ 'https://XXXX.herokuapp.com']
  config.action_cable.disable_request_forgery_protection = true

Gemfile.lock related gems: sidekiq (6.5.12) connection_pool (>= 2.2.5, < 3) rack (~> 2.0) redis (>= 4.5.0, < 5)

thanks !

byroot commented 4 months ago

no implicit conversion of String into Integer suggest it's trying to use a string key on an array,. e.g.:

foo = []
foo["blah"]

It's not clear from the information you posted what exactly is wrong, but something must be wrong.

Either way, I'm quite certain the issue isn't in redis-rb but even it it was, 4.x is EOL so nothing for me to do.

I suggest you put some debug statement in that code to see what value is being passed.