I have an issue with a Sidekiq (6.2.1) and Redis (4.4.0) running with docker-compose. I found nothing useful on internet, Redis is up and running, it also seems that Sidekiq can connect but then, Sidekiq exits at start because of some kind of concurrency:
sidekiq | 2021-10-04T19:44:53.214Z pid=1 tid=2zt WARN: Errno::EALREADY: Operation already in progress - connect(2) for 172.18.0.2:6379
sidekiq | 2021-10-04T19:44:53.214Z pid=1 tid=2zt WARN: /usr/local/lib/ruby/3.0.0/socket.rb:1214:in `__connect_nonblock'
The above is extracted from the full trace:
$ docker-compose up
Starting redis ... done
Starting db ... done
Starting web ... done
Starting sidekiq ... done
Attaching to redis, db, sidekiq, web
db |
db | PostgreSQL Database directory appears to contain a database; Skipping initialization
db |
db | 2021-10-04 19:44:49.879 UTC [1] LOG: starting PostgreSQL 14.0 (Debian 14.0-1.pgdg110 1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
db | 2021-10-04 19:44:49.880 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db | 2021-10-04 19:44:49.880 UTC [1] LOG: listening on IPv6 address "::", port 5432
db | 2021-10-04 19:44:49.884 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db | 2021-10-04 19:44:49.891 UTC [27] LOG: database system was shut down at 2021-10-04 19:43:16 UTC
db | 2021-10-04 19:44:49.897 UTC [1] LOG: database system is ready to accept connections
redis | 1:C 04 Oct 2021 19:44:49.788 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis | 1:C 04 Oct 2021 19:44:49.788 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis | 1:C 04 Oct 2021 19:44:49.788 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis | 1:M 04 Oct 2021 19:44:49.789 * monotonic clock: POSIX clock_gettime
redis | 1:M 04 Oct 2021 19:44:49.789 * Running mode=standalone, port=6379.
redis | 1:M 04 Oct 2021 19:44:49.790 # Server initialized
redis | 1:M 04 Oct 2021 19:44:49.790 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis | 1:M 04 Oct 2021 19:44:49.790 * Loading RDB produced by version 6.2.5
redis | 1:M 04 Oct 2021 19:44:49.790 * RDB age 93 seconds
redis | 1:M 04 Oct 2021 19:44:49.790 * RDB memory usage when created 0.78 Mb
redis | 1:M 04 Oct 2021 19:44:49.790 * DB loaded from disk: 0.000 seconds
redis | 1:M 04 Oct 2021 19:44:49.790 * Ready to accept connections
sidekiq | 2021-10-04T19:44:52.999Z pid=1 tid=2zt INFO: Booting Sidekiq 6.2.1 with redis options {:url=>"redis://redis", :port=>"6379", :db=>"1"}
web | => Booting Puma
web | => Rails 6.1.4.1 application starting in development
web | => Run `bin/rails server --help` for more startup options
sidekiq | 2021-10-04T19:44:53.211Z pid=1 tid=2zt INFO: Booted Rails 6.1.4.1 application in development environment
sidekiq | 2021-10-04T19:44:53.212Z pid=1 tid=2zt INFO: Running in ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
sidekiq | 2021-10-04T19:44:53.212Z pid=1 tid=2zt INFO: See LICENSE and the LGPL-3.0 for licensing details.
sidekiq | 2021-10-04T19:44:53.212Z pid=1 tid=2zt INFO: Upgrade to Sidekiq Pro for more features and support: https://sidekiq.org
sidekiq | 2021-10-04T19:44:53.214Z pid=1 tid=2zt WARN: Errno::EALREADY: Operation already in progress - connect(2) for 172.18.0.2:6379
sidekiq | 2021-10-04T19:44:53.214Z pid=1 tid=2zt WARN: /usr/local/lib/ruby/3.0.0/socket.rb:1214:in `__connect_nonblock'
sidekiq | /usr/local/lib/ruby/3.0.0/socket.rb:1214:in `connect_nonblock'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/connection/ruby.rb:159:in `rescue in connect_addrinfo'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/connection/ruby.rb:153:in `connect_addrinfo'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/connection/ruby.rb:192:in `block in connect'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/connection/ruby.rb:190:in `each'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/connection/ruby.rb:190:in `each_with_index'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/connection/ruby.rb:190:in `connect'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/connection/ruby.rb:304:in `connect'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/client.rb:371:in `establish_connection'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/client.rb:117:in `block in connect'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/client.rb:330:in `with_reconnect'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/client.rb:116:in `connect'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/client.rb:403:in `ensure_connected'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/client.rb:255:in `block in process'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/client.rb:342:in `logging'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/client.rb:254:in `process'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis/client.rb:148:in `call'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis.rb:307:in `block in info'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis.rb:70:in `block in synchronize'
sidekiq | /usr/local/lib/ruby/3.0.0/monitor.rb:202:in `synchronize'
sidekiq | /usr/local/lib/ruby/3.0.0/monitor.rb:202:in `mon_synchronize'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis.rb:70:in `synchronize'
sidekiq | /usr/local/bundle/gems/redis-4.4.0/lib/redis.rb:306:in `info'
sidekiq | /usr/local/bundle/gems/sidekiq-6.2.1/lib/sidekiq.rb:120:in `block in redis_info'
sidekiq | /usr/local/bundle/gems/sidekiq-6.2.1/lib/sidekiq.rb:98:in `block in redis'
sidekiq | /usr/local/bundle/gems/connection_pool-2.2.5/lib/connection_pool.rb:63:in `block (2 levels) in with'
sidekiq | /usr/local/bundle/gems/connection_pool-2.2.5/lib/connection_pool.rb:62:in `handle_interrupt'
sidekiq | /usr/local/bundle/gems/connection_pool-2.2.5/lib/connection_pool.rb:62:in `block in with'
sidekiq | /usr/local/bundle/gems/connection_pool-2.2.5/lib/connection_pool.rb:59:in `handle_interrupt'
sidekiq | /usr/local/bundle/gems/connection_pool-2.2.5/lib/connection_pool.rb:59:in `with'
sidekiq | /usr/local/bundle/gems/sidekiq-6.2.1/lib/sidekiq.rb:95:in `redis'
sidekiq | /usr/local/bundle/gems/sidekiq-6.2.1/lib/sidekiq.rb:114:in `redis_info'
sidekiq | /usr/local/bundle/gems/sidekiq-6.2.1/lib/sidekiq/cli.rb:62:in `run'
sidekiq | /usr/local/bundle/gems/sidekiq-6.2.1/bin/sidekiq:31:in `<top (required)>'
sidekiq | /usr/local/bundle/bin/sidekiq:23:in `load'
sidekiq | /usr/local/bundle/bin/sidekiq:23:in `<top (required)>'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `load'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `kernel_load'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/cli/exec.rb:28:in `run'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/cli.rb:474:in `exec'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/cli.rb:30:in `dispatch'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/cli.rb:24:in `start'
sidekiq | /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/libexec/bundle:49:in `block in <top (required)>'
sidekiq | /usr/local/lib/ruby/3.0.0/bundler/friendly_errors.rb:128:in `with_friendly_errors'
sidekiq | /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.22/libexec/bundle:37:in `<top (required)>'
sidekiq | /usr/local/bin/bundle:23:in `load'
sidekiq | /usr/local/bin/bundle:23:in `<main>'
sidekiq exited with code 1
web | [1] Puma starting in cluster mode...
web | [1] * Puma version: 5.4.0 (ruby 3.0.2-p107) ("Super Flight")
web | [1] * Min threads: 5
web | [1] * Max threads: 5
web | [1] * Environment: development
web | [1] * Master PID: 1
web | [1] * Workers: 2
web | [1] * Restarts: (✔) hot (✖) phased
web | [1] * Preloading application
web | [1] * Listening on http://0.0.0.0:3000
web | [1] Use Ctrl-C to stop
web | [1] - Worker 0 (PID: 10) booted in 0.33s, phase: 0
web | [1] - Worker 1 (PID: 12) booted in 0.33s, phase: 0
^CGracefully stopping... (press Ctrl C again to force)
Stopping web ... done
Stopping db ... done
Stopping redis ... done
I don't understand why and I can't tell since when it doesn't work, I don't think I have touch something related to this recently.
Here are my other files:
sidekiq.rb
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_PROVIDER_URL'],
port: ENV['REDIS_PROVIDER_PORT'],
db: ENV['REDIS_PROVIDER_DB']
}
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDIS_PROVIDER_URL'],
port: ENV['REDIS_PROVIDER_PORT'],
db: ENV['REDIS_PROVIDER_DB']
}
end
redis.rb
# Connection to the redis database
Redis.current = Redis.new(url: ENV['REDIS_PROVIDER_URL'],
port: ENV['REDIS_PROVIDER_PORT'],
db: ENV['REDIS_PROVIDER_DB'])
.env
REDIS_PROVIDER_DB=1
REDIS_PROVIDER_URL=redis://redis
REDIS_PROVIDER_PORT=6379
docker-compose.yml
version: "3"
services:
web: &web
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0' -e ${RAILS_ENV}"
container_name: web
image: worldofstarsregistry.azurecr.io/web
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
- redis
env_file:
- '.env'
db:
restart: always
image: postgres
container_name: db
volumes:
- ./db/postgres-data/:/var/lib/postgresql/data
ports:
- "5432:5432"
env_file:
- '.env'
redis:
restart: always
image: "redis:alpine"
command: redis-server
container_name: redis
ports:
- "6379:6379"
volumes:
- './redis-data:/data'
sidekiq:
build: .
container_name: sidekiq
image: worldofstarsregistry.azurecr.io/sidekiq
volumes:
- .:/myapp
- '/myapp/tmp' # don't mount tmp directory
depends_on:
- db
- redis
command: bash -c "bundle exec sidekiq -C config/sidekiq.yml"
env_file:
- '.env'
volumes:
redis:
postgres:
Dockerfile
FROM ruby:3
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
COPY entrypoint.sh /usr/bin/
RUN chmod x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]
entrypoint.sh
#!/bin/bash
set -e
# remove a potentially pre-existing server.pid for Rails
rm -f /myapp/tmp/pids/server.pid
# then exec the container's main process
exec "$@"
Thank you for any tips!
CodePudding user response:
After rebooting my computer, it now works...