无法修改冻结的哈希 - rails 6 heroku

can't modify frozen Hash - rails 6 heroku

更新到 Rails 6 并推送到 Heroku 后,我收到此错误。我找不到任何类似的问题,也不明白错误的意思。

我已确认数据库、用户名、密码和主机位置都是准确的。

2021-05-04T15:01:04.536128+00:00 heroku[worker.1]: State changed from crashed to starting
2021-05-04T15:01:24.086595+00:00 heroku[worker.1]: Starting process with command `bundle exec sidekiq -e production -C config/sidekiq.yml`
2021-05-04T15:01:24.897839+00:00 heroku[worker.1]: State changed from starting to up
2021-05-04T03:11:56.114768+00:00 app[worker.2]: I, [2021-05-04T03:11:56.114626 #4]  INFO -- sentry: ** [Raven] Raven 3.1.2 ready to catch errors
    2021-05-04T03:11:56.708882+00:00 app[worker.2]: can't modify frozen Hash: {:adapter=>"postgresql", :pool=>5, :timeout=>10000, :database=>"real_db", :username=>"real_username", :password=>"real_password", :host=>"real_location.compute-1.amazonaws.com", :port=>5432}
    2021-05-04T03:11:56.708922+00:00 app[worker.2]: /app/config/initializers/sidekiq.rb:6:in `block in <top (required)>'
    2021-05-04T03:11:56.708923+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/sidekiq-5.2.9/lib/sidekiq.rb:75:in `configure_server'
    2021-05-04T03:11:56.708924+00:00 app[worker.2]: /app/config/initializers/sidekiq.rb:5:in `<top (required)>'
    2021-05-04T03:11:56.708925+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:326:in `load'
    2021-05-04T03:11:56.708926+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:326:in `block in load'
    2021-05-04T03:11:56.708926+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:299:in `load_dependency'
    2021-05-04T03:11:56.708927+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:326:in `load'
    2021-05-04T03:11:56.708927+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/engine.rb:681:in `block in load_config_initializer'
    2021-05-04T03:11:56.708927+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/notifications.rb:205:in `instrument'
    2021-05-04T03:11:56.708928+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/engine.rb:680:in `load_config_initializer'
    2021-05-04T03:11:56.708928+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/engine.rb:634:in `block (2 levels) in <class:Engine>'
    2021-05-04T03:11:56.708929+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/engine.rb:633:in `each'
    2021-05-04T03:11:56.708929+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/engine.rb:633:in `block in <class:Engine>'
    2021-05-04T03:11:56.708929+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:32:in `instance_exec'
    2021-05-04T03:11:56.708930+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:32:in `run'
    2021-05-04T03:11:56.708930+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:61:in `block in run_initializers'
    2021-05-04T03:11:56.708930+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:228:in `block in tsort_each'
    2021-05-04T03:11:56.708931+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    2021-05-04T03:11:56.708931+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
    2021-05-04T03:11:56.708931+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:431:in `each_strongly_connected_component_from'
    2021-05-04T03:11:56.708932+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
    2021-05-04T03:11:56.708932+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:50:in `each'
    2021-05-04T03:11:56.708932+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:50:in `tsort_each_child'
    2021-05-04T03:11:56.708933+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:415:in `call'
    2021-05-04T03:11:56.708933+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:415:in `each_strongly_connected_component_from'
    2021-05-04T03:11:56.708933+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:349:in `block in each_strongly_connected_component'
    2021-05-04T03:11:56.708934+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:347:in `each'
    2021-05-04T03:11:56.708934+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:347:in `call'
    2021-05-04T03:11:56.708934+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:347:in `each_strongly_connected_component'
    2021-05-04T03:11:56.708935+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:226:in `tsort_each'
    2021-05-04T03:11:56.708935+00:00 app[worker.2]: /app/vendor/ruby-3.0.1/lib/ruby/3.0.0/tsort.rb:205:in `tsort_each'
    2021-05-04T03:11:56.708935+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/initializable.rb:60:in `run_initializers'
    2021-05-04T03:11:56.708935+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.3.1/lib/rails/application.rb:384:in `initialize!'
    2021-05-04T03:11:56.708936+00:00 app[worker.2]: /app/config/environment.rb:5:in `<top (required)>'
    2021-05-04T03:11:56.708936+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `require'
    2021-05-04T03:11:56.708936+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `block in require'
    2021-05-04T03:11:56.708937+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:299:in `load_dependency'
    2021-05-04T03:11:56.708937+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.3.1/lib/active_support/dependencies.rb:332:in `require'
    2021-05-04T03:11:56.708937+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/sidekiq-5.2.9/lib/sidekiq/cli.rb:288:in `boot_system'
    2021-05-04T03:11:56.708938+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/sidekiq-5.2.9/lib/sidekiq/cli.rb:46:in `run'
    2021-05-04T03:11:56.708938+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/sidekiq-5.2.9/bin/sidekiq:12:in `<top (required)>'
    2021-05-04T03:11:56.708938+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/bin/sidekiq:23:in `load'
    2021-05-04T03:11:56.708939+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/bin/sidekiq:23:in `<top (required)>'
    2021-05-04T03:11:56.708939+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/cli/exec.rb:63:in `load'
    2021-05-04T03:11:56.708945+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/cli/exec.rb:63:in `kernel_load'
    2021-05-04T03:11:56.708945+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/cli/exec.rb:28:in `run'
    2021-05-04T03:11:56.708945+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/cli.rb:494:in `exec'
    2021-05-04T03:11:56.708946+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    2021-05-04T03:11:56.708946+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    2021-05-04T03:11:56.708946+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
    2021-05-04T03:11:56.708947+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/cli.rb:30:in `dispatch'
    2021-05-04T03:11:56.708947+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
    2021-05-04T03:11:56.708947+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/cli.rb:24:in `start'
    2021-05-04T03:11:56.708948+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/exe/bundle:49:in `block in <top (required)>'
    2021-05-04T03:11:56.708948+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/lib/bundler/friendly_errors.rb:130:in `with_friendly_errors'
    2021-05-04T03:11:56.708948+00:00 app[worker.2]: /app/vendor/bundle/ruby/3.0.0/gems/bundler-2.2.16/exe/bundle:37:in `<top (required)>'
    2021-05-04T03:11:56.708964+00:00 app[worker.2]: /app/bin/bundle:3:in `load'
    2021-05-04T03:11:56.708965+00:00 app[worker.2]: /app/bin/bundle:3:in `<main>'
    2021-05-04T03:11:56.773370+00:00 heroku[worker.2]: Process exited with status 1
    2021-05-04T03:11:57.188558+00:00 heroku[worker.2]: State changed from up to crashed

似乎引用了 sidekiq 初始值设定项的第 6 行,但我没有发现任何可疑之处。事实上,自从几年前设置以来,它真的没有改变过:

if Rails.env.production?

require 'sidekiq/web'

  Sidekiq.configure_server do |config|
    ActiveRecord::Base.configurations[Rails.env.to_s]['pool'] = 30
  end
end

sidekiq.yml:

development:
  :concurrency: 5
production:
  :concurrency: 20
:queues:
  - default
  - mailers

过程文件

web: bundle exec puma -p $PORT  ./config.ru
web: bundle exec puma -C config/puma.rb
redis: redis-server
worker: bundle exec sidekiq -e production -C config/sidekiq.yml

看起来配置散列自此提交后已被冻结:https://github.com/rails/rails/commit/2291d4a94fd3aff61c77d1a2ad1e6186ed4c80a2ActiveRecord::Base.configurations[Rails.env.to_s]['pool'] = 30 在你的 Sidekiq 初始化器中试图改变冻结的散列。

如果您在 config.database.yml 文件中配置数据库,您可以在那里添加或更新生产池的大小,并删除整个 Sidekiq.configure_server 块:

production:
  username: <%= ENV['DATABASE_USERNAME'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>
  pool: 30

如果您完全通过 DATABASE_URL 环境变量配置数据库,则只需确保在 URL:

末尾指定池大小
postgresql://username:password@host:5432/database-name?pool=30

更多信息在这里:https://edgeguides.rubyonrails.org/configuring.html#configuring-a-database

Sidekiq 初始化程序:

require 'sidekiq/web' if Rails.env.production?