Sidekiq - Errno::EALREADY:操作已在进行中

Sidekiq - Errno::EALREADY: Operation already in progress

我对 Sidekiq (6.2.1) 和 Redis (4.4.0) 运行 docker-compose 有疑问。我在互联网上找不到任何有用的东西,Redis 已启动并且 运行,Sidekiq 似乎也可以连接,但是由于某种并发性,Sidekiq 在启动时退出:

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'

以上是从完整的跟踪中提取的:

$ 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

我不明白为什么,也不知道是什么时候不起作用的,我想我最近没有接触过与此相关的东西。

这是我的其他文件:

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 "$@"

感谢您的任何提示!

重新启动计算机后,它现在可以工作了...