Redis / Sidekiq background job failing

Hey,

I’m working on this Ruby On Rails 7 application. I don’t know much about deployments, it is my first experience using Render and deploying a Full Stack Web App.

I have installed sidekiq and redis gems already

This is my render.yml file

databases:
  - name: postgres
    ipAllowList: []

services:
  - type: web
    name: rails
    plan: free
    env: ruby
    buildCommand: "./bin/render-build.sh"
    startCommand: bundle exec rails s
    envVars:
      - key: RAILS_MASTER_KEY
        sync: false
      - key: DATABASE_URL
        fromDatabase:
          name: postgres
          property: connectionString
      - key: REDIS_URL
        fromService:
          type: redis
          name: redis
          property: connectionString

  - type: redis
    name: redis
    region: ohio
    ipAllowList: []
    maxmemoryPolicy: noeviction

  - type: worker
    name: sidekiq-worker
    env: ruby
    region: ohio
    buildCommand: bundle install
    startCommand: bundle exec sidekiq
    envVars:
      - key: REDIS_URL
        fromService:
          type: redis
          name: redis
          property: connectionString
      - key: RAILS_MASTER_KEY
        sync: false

This is my sidekiq.rb file

Sidekiq.configure_server do |config|
  config.redis = { url: ENV["REDIS_URL"] }
end

Sidekiq.configure_client do |config|
  config.redis = { url: ENV["REDIS_URL"] }
end

In my Redis service I copied the Internal Redis URL provided by render and set it in my Web Service as an ENV variable, and also did it for the Worker Service

The Worker service is failing while the others (database, web service, and redis) are available.

This are the logs of my Worker

==> Starting service with 'bundle exec sidekiq'
Mar 23 04:33:41 PM  2023-03-23T20:33:41.789Z pid=68 tid=2ks INFO: Booted Rails 7.0.4.2 application in production environment
Mar 23 04:33:41 PM  2023-03-23T20:33:41.789Z pid=68 tid=2ks INFO: Running in ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x86_64-linux]
Mar 23 04:33:41 PM  2023-03-23T20:33:41.789Z pid=68 tid=2ks INFO: See LICENSE and the LGPL-3.0 for licensing details.
Mar 23 04:33:41 PM  2023-03-23T20:33:41.789Z pid=68 tid=2ks INFO: Upgrade to Sidekiq Pro for more features and support: https://sidekiq.org
Mar 23 04:33:41 PM  2023-03-23T20:33:41.789Z pid=68 tid=2ks INFO: Sidekiq 7.0.7 connecting to Redis with options {:size=>5, :pool_name=>"internal", :url=>"redis://red-cgc7iqo2qv267udbeaf0:6379"}
Mar 23 04:33:41 PM  getaddrinfo: Name or service not known
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/3.1.0/socket.rb:227:in `getaddrinfo'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/3.1.0/socket.rb:227:in `foreach'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/3.1.0/socket.rb:632:in `tcp'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/redis-client-0.14.0/lib/redis_client/ruby_connection.rb:111:in `connect'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/redis-client-0.14.0/lib/redis_client/ruby_connection.rb:49:in `initialize'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/redis-client-0.14.0/lib/redis_client.rb:671:in `new'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/redis-client-0.14.0/lib/redis_client.rb:671:in `block in connect'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/redis-client-0.14.0/lib/redis_client/middlewares.rb:12:in `connect'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/redis-client-0.14.0/lib/redis_client.rb:670:in `connect'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/redis-client-0.14.0/lib/redis_client.rb:657:in `raw_connection'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/redis-client-0.14.0/lib/redis_client.rb:624:in `ensure_connected'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/redis-client-0.14.0/lib/redis_client.rb:209:in `call'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/redis-client-0.14.0/lib/redis_client/decorator.rb:26:in `call'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/sidekiq-7.0.7/lib/sidekiq/config.rb:137:in `block in redis_info'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/sidekiq-7.0.7/lib/sidekiq/config.rb:156:in `block in redis'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/connection_pool-2.3.0/lib/connection_pool.rb:65:in `block (2 levels) in with'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/connection_pool-2.3.0/lib/connection_pool.rb:64:in `handle_interrupt'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/connection_pool-2.3.0/lib/connection_pool.rb:64:in `block in with'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/connection_pool-2.3.0/lib/connection_pool.rb:61:in `handle_interrupt'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/connection_pool-2.3.0/lib/connection_pool.rb:61:in `with'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/sidekiq-7.0.7/lib/sidekiq/config.rb:153:in `redis'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/sidekiq-7.0.7/lib/sidekiq/config.rb:136:in `redis_info'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/sidekiq-7.0.7/lib/sidekiq/cli.rb:75:in `run'
Mar 23 04:33:41 PM  /opt/render/project/.gems/ruby/3.1.0/gems/sidekiq-7.0.7/bin/sidekiq:31:in `<top (required)>'
Mar 23 04:33:41 PM  /opt/render/project/.gems/bin/sidekiq:27:in `load'
Mar 23 04:33:41 PM  /opt/render/project/.gems/bin/sidekiq:27:in `<top (required)>'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/cli/exec.rb:58:in `load'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/cli/exec.rb:58:in `kernel_load'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/cli/exec.rb:23:in `run'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/cli.rb:492:in `exec'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/cli.rb:34:in `dispatch'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/cli.rb:28:in `start'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.9/exe/bundle:45:in `block in <top (required)>'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
Mar 23 04:33:41 PM  /opt/render/project/rubies/ruby-3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.9/exe/bundle:33:in `<top (required)>'
Mar 23 04:33:41 PM  /opt/render/project/.gems/bin/bundle:113:in `load'
Mar 23 04:33:41 PM  /opt/render/project/.gems/bin/bundle:113:in `<main>'

As you can see it says getaddrinfo: Name or service not known, but haven’t been able to spot what I’m missing or doing wrong

I remember having similar issues getting my Sidekiq configured, but I don’t remember the exact details. If it helps, here’s my start command:

bundle exec sidekiq -e production -C config/sidekiq.yml

and here’s my sidekiq.yml:

---
:concurrency: <%= ENV['SIDEKIQ_CONCURRENCY'].to_i %>
:logfile: ./log/sidekiq.log
production:
  :concurrency: <%= ENV['SIDEKIQ_CONCURRENCY'].to_i %>
:queues:
  - critical
  - active_storage_analysis
  - mailers
  - default
  - active_storage_purge
  - low
  - extralow

and my sidekiq.rb is the same as yours.

after looking at your log again, it seems like the connection to Redis is the problem. Maybe double check the connection string is correct. Here’s what’s in my log during a deploy:

Mar 24 07:06:23 PM  ==> Starting service with 'bundle exec sidekiq -e production -C config/sidekiq.yml'
Mar 24 07:06:33 PM  2023-03-24T23:06:33.446Z pid=68 tid=2x8 INFO: Booted Rails 7.0.4.1 application in production environment
Mar 24 07:06:33 PM  2023-03-24T23:06:33.493Z pid=68 tid=2x8 INFO: Running in ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) +YJIT [x86_64-linux]
Mar 24 07:06:33 PM  2023-03-24T23:06:33.493Z pid=68 tid=2x8 INFO: See LICENSE and the LGPL-3.0 for licensing details.
Mar 24 07:06:33 PM  2023-03-24T23:06:33.493Z pid=68 tid=2x8 INFO: Upgrade to Sidekiq Pro for more features and support: https://sidekiq.org
Mar 24 07:06:33 PM  2023-03-24T23:06:33.494Z pid=68 tid=2x8 INFO: Sidekiq 7.0.3 connecting to Redis with options {:size=>5, :pool_name=>"internal", :url=>"redis://red-cco7lxxxxxxxxxxxxx0:6379/10"}
Mar 24 07:06:33 PM  2023-03-24T23:06:33.500Z pid=68 tid=2x8 INFO: Sidekiq 7.0.3 connecting to Redis with options {:size=>3, :pool_name=>"default", :url=>"redis://red-cco7lxxxxxxxxxxxxx0:6379/10"}
Mar 24 07:07:14 PM  2023-03-24T23:07:14.853Z pid=68 tid=1ry8 class=StockTaggerJob jid=de29628315a1bbe1bade73e7 INFO: start

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.