0
votes

I have a rails app with puma deployed on heroku. Everything seems to be fine except if I start my app in dev env the port is 5000 instead of 3000.

Why is this happening? According to my config file it should fall back to 3000 like just the thread and concurrency numbers (those work fine).

Procfile.dev

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

config/puma.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['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
  ActiveRecord::Base.establish_connection
end

After starting server with foreman start -f Procfile.dev

12:36:51 web.1     | [12816] Puma starting in cluster mode...
12:36:51 web.1     | [12816] * Version 2.13.4 (ruby 2.2.3-p173), codename: A Midsummer Code's Dream
12:36:51 web.1     | [12816] * Min threads: 5, max threads: 5
12:36:51 web.1     | [12816] * Environment: development
12:36:51 web.1     | [12816] * Process workers: 2
12:36:51 web.1     | [12816] * Preloading application
12:37:08 web.1     | [12816] * Listening on tcp://0.0.0.0:5000
12:37:08 web.1     | [12816] ! WARNING: Detected 1 Thread(s) started in app boot:
12:37:08 web.1     | [12816] ! #<Rack::MiniProfiler::FileStore::CacheCleanupThread:0x007f860f8fa628@/Users/Silo/.rvm/gems/ruby-2.2.3/gems/rack-mini-profiler-0.9.8/lib/mini_profiler/storage/file_store.rb:53 sleep> - /Users/Silo/.rvm/gems/ruby-2.2.3/gems/rack-mini-profiler-0.9.8/lib/mini_profiler/storage/file_store.rb:71:in `sleep'
12:37:08 web.1     | [12816] Use Ctrl-C to stop
12:37:08 web.1     | [12816] - Worker 0 (pid: 12822) booted, phase: 0
12:37:08 web.1     | [12816] - Worker 1 (pid: 12823) booted, phase: 0
1

1 Answers

3
votes

As for the why, foreman passes $PORT to your process, which is set to 5000 by default. Consequently, port 3000 is ignored in your config/puma.rb. See at the end of this thread https://github.com/ddollar/foreman/issues/381

Now, there are several ways to solve this. For instance, you can just start foreman as follows: foreman s -p 3000. This is my preferred solution since it does not involve creating a specific procfile for development, nor adding to .env file (PORT=3000), nor creating a .foreman file (port: 3000).

If you really want to use your development procfile, change it as follows: web: PORT=3000 bundle exec puma -C config/puma.rb