Heroku 应用程序错误应用程序无法上线

Heroku Application Error App don't go Live

好吧,我正在尝试使用 Heroku 部署我的应用程序,但我遇到了一些错误,我的互联网挖掘不足以解决这些错误。部署顺利,表明它是成功的:

remote: Verifying deploy... done.
   To https://git.heroku.com/MYAPPHERE.git
      7715c7c..c85251d  master -> master

但是当我访问该域时,它显示了这条消息:

"Application Error, An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details."

我的日志显示:

018-05-18T19:14:24.000000+00:00 app[api]: Build succeeded
2018-05-18T19:14:28.864974+00:00 heroku[web.1]: Starting process with command `bundle exec puma -C config/puma.rb`
2018-05-18T19:14:31.064709+00:00 app[web.1]: [4] Puma starting in cluster mode...
2018-05-18T19:14:31.064729+00:00 app[web.1]: [4] * Version 3.11.4 (ruby 2.3.1-p112), codename: Love Song
2018-05-18T19:14:31.064730+00:00 app[web.1]: [4] * Min threads: 5, max threads: 5
2018-05-18T19:14:31.064732+00:00 app[web.1]: [4] * Environment: production
2018-05-18T19:14:31.064752+00:00 app[web.1]: [4] * Process workers: 2
2018-05-18T19:14:31.064776+00:00 app[web.1]: [4] * Preloading application
2018-05-18T19:14:33.736893+00:00 app[web.1]: [4] * Listening on tcp://0.0.0.0:36902
2018-05-18T19:14:33.737145+00:00 app[web.1]: [4] * Listening on tcp://0.0.0.0:36902
2018-05-18T19:14:33.737416+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.3.0/bin/puma)
2018-05-18T19:14:33.737462+00:00 app[web.1]: Errno::EADDRINUSE: Address already in use - bind(2) for "0.0.0.0" port 36902
2018-05-18T19:14:33.737465+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/binder.rb:270:in `initialize'
2018-05-18T19:14:33.737466+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/binder.rb:270:in `new'
2018-05-18T19:14:33.737468+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/binder.rb:270:in `add_tcp_listener'
2018-05-18T19:14:33.737469+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/binder.rb:105:in `block in parse'
2018-05-18T19:14:33.737471+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/binder.rb:88:in `each'
2018-05-18T19:14:33.737472+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/binder.rb:88:in `parse'
2018-05-18T19:14:33.737474+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/runner.rb:144:in `load_and_bind'
2018-05-18T19:14:33.737475+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/cluster.rb:397:in `run'
2018-05-18T19:14:33.737477+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/launcher.rb:184:in `run'
2018-05-18T19:14:33.737478+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/lib/puma/cli.rb:78:in `run'
2018-05-18T19:14:33.737480+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/puma-3.11.4/bin/puma:10:in `<top (required)>'
2018-05-18T19:14:33.737482+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/puma:23:in `load'
2018-05-18T19:14:33.737483+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/bin/puma:23:in `<top (required)>'
2018-05-18T19:14:33.833127+00:00 heroku[web.1]: State changed from starting to up
2018-05-18T19:14:33.953708+00:00 heroku[web.1]: State changed from up to crashed
2018-05-18T19:14:33.931364+00:00 heroku[web.1]: Process exited with status 1
2018-05-18T19:14:35.621801+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=MYAPPNAME request_id=74c67c85-dce7-4da8-9770-f41513d8cf31 fwd="179.178.13.25" dyno= connect= service= status=503 bytes= protocol=https

在我的 gemfile 上:

# Use Puma as the app server
gem 'puma', '~> 3.7'

在 config/puma 上:

plugin :tmp_restart

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  # Worker specific setup for Rails 4.1+
  # See: https://devcenter.heroku.com/articles/
  # deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  ActiveRecord::Base.establish_connection
end

我看到地址发生了错误,但我根本不使用这个地址做任何事情。我试过 运行 lsof -wni tcp:36902 但它什么也没显示。

希望我提供了足够的信息。

似乎 puma 试图绑定听众两次:

2018-05-18T19:14:33.736893+00:00 app[web.1]: [4] * Listening on tcp://0.0.0.0:36902
2018-05-18T19:14:33.737145+00:00 app[web.1]: [4] * Listening on tcp://0.0.0.0:36902

您可能想尝试将 preload_app! 移动到您的端口和环境配置下方。 (通过调用port,可能会调用两个bind函数similar to here

我目前是 运行 Heroku w/ puma 3.11.4,我的 config/puma.rb 看起来像:

 threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
 threads threads_count, threads_count

 environment ENV.fetch('RAILS_ENV', 'development')
 port        ENV.fetch('PORT', 3000)

 workers ENV.fetch('WEB_CONCURRENCY', 2)

 preload_app!

 before_fork do
   ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
 end

 on_worker_boot do
   ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
 end

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

查看您的 Procfile 可能也会有所帮助。只是想确认它看起来像:

一个简单的 Procfile 可能是:

web: bundle exec puma -C config/puma.rb