如何修复ruby on rails应用程序崩溃时的heroku H10/Application错误?

j8ag8udp  于 2023-11-19  发布在  Ruby
关注(0)|答案(1)|浏览(118)

在过去的4个小时里,我一直试图修复heroku(ruby on rails应用程序)上的应用程序错误,但没有运气。
P.S应用程序在本地运行良好

2023-10-30T14:40:44.484063+00:00 heroku[web.1]: State changed from up to crashed
2023-10-30T14:40:44.378048+00:00 heroku[router]: at=info method=GET path="/cable" host=j-a-m-1f39b9aba9a4.herokuapp.com request_id=2b4b5435-b40a-431c-b48f-1159fa5fd7fb fwd="86.182.36.176" dyno=web.1 connect=0ms service=107ms status=101 bytes=174 protocol=https
2023-10-30T14:41:19.466343+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/cable" host=j-a-m-1f39b9aba9a4.herokuapp.com request_id=41cf02af-42a1-43b5-9ac8-7d6fbf8ac59f fwd="86.182.36.176" dyno= connect= service= status=503 bytes= protocol=https
2023-10-30T14:41:19.652461+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/cable" host=j-a-m-1f39b9aba9a4.herokuapp.com request_id=3fd8c5e8-b470-4c2c-86cd-a6c5ac86246b fwd="86.182.36.176" dyno= connect= service= status=503 bytes= protocol=https
2023-10-30T14:41:27.250890+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/cable" host=j-a-m-1f39b9aba9a4.herokuapp.com request_id=255ce216-77ae-465a-9abb-f32e5b027221 fwd="86.182.36.176" dyno= connect= service= status=503 bytes= protocol=https

字符串
我已经尝试重启heroku很多次了,确保我的storage.yml文件格式正确,在heroku控制台中没有发现错误。这可能与我的procfile有关,但我尝试的所有操作都返回相同的错误。我还重启了heroku界面上的所有web dynos。
Procfile:web:bundle exec puma -C config/puma.rb
gem文件:

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'sqlite3'

ruby "3.1.2"

gem "devise"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.7", ">= 7.0.7.2"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use postgresql as the database for Active Record
# gem "pg", "~> 1.1"

group :production do
  gem 'pg'
  gem 'redis', '~> 4.0'
end
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Sass to process CSS
gem "sassc-rails"
gem 'sidekiq'
gem 'thin'

# added faker
gem "faker"

gem "rails-ujs"

# spotify api
# gem 'rack-cors'
# gem 'active_model_serializers'
# gem 'rspotify'

# added cloudinary
gem "cloudinary"

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

gem "bootstrap", "~> 5.2"

gem "autoprefixer-rails"

gem "font-awesome-sass", "~> 6.1"

gem "simple_form", github: "heartcombo/simple_form"

group :development, :test do
  # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
  gem "debug", platforms: %i[ mri mingw x64_mingw ]
  gem "dotenv-rails"
end

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem "web-console"

  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  # gem "rack-mini-profiler"

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem "spring"
end

group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem "capybara"
  gem "selenium-webdriver"
  gem "webdrivers"
end

g6ll5ycj

g6ll5ycj1#

解决方案:我已经修复了应用程序。问题是我的puma文件是为开发而设置的,而它应该是生产的。我项目中的Procfile指定了“web”进程类型的命令,该进程类型负责运行应用程序服务器。
命令“bundle exec puma -C config/puma.rb”告诉Puma如何启动应用程序。然而,我注意到Puma文件(config/puma.rb)中的配置是为开发而设置的。
为了确保正确的生产设置,我调整了config/puma.rb文件中的Puma配置,以匹配生产环境的要求。
我所做的就是将开发的地方改为生产,并取消注解了preload_app!。下面是我的Puma文件:

# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count

# Specifies the `worker_timeout` threshold that Puma will use to wait before
# terminating a worker in development environments.
#
worker_timeout 3600 if ENV.fetch("RAILS_ENV", "production") == "production"

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "production" }

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
workers ENV.fetch("WEB_CONCURRENCY") { 2 }

# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
preload_app!

# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart

字符串

相关问题