Puma config in development vs on Heroku

So that puma web server for ruby, the web server that’s built for speed and concurrency has a weird issue with its configuration on development environment vs on Heroku.

For those of who might not know, this is the puma web server I’m talking about

https://github.com/puma/puma

Yeah, the one that’s apparently the standard that comes with Rails 5 now.

One of the projects I’m consulting for (yes, it’s a Rails project) uses puma as its web server. And it has a puma.rb file that’s configured as recommended by Heroku. The file at config/puma.rb looks like

Now, you see on line 8 and 9 there? Despite the ruby code checking for the nil condition and defaulting to port 3000 and an environment of development if those environment variables are nil, this does not work in development mode if we run it with foreman with a Procfile. For some reason, the port for puma in development mode defaults to 5000 instead of 3000.

Now, if we put an = sign in front of the port and environment declarations like this

Then it works on development and the port for puma defaults to 3000. However, putting those = signs will break the Heroku server.

After wrestling with it for an hour, I simply decided to set the environment variables of PORT and RACK_ENV to 3000 and development accordingly on my development environment so that at least the application runs without crashing on Heroku.

It’s a super weird issue and I’m not sure why it’s working well on development and then goes haywire on Heroku. At any rate, for those who are running into the same issue, I hope this post was helpful.

About the Author Chris Jeon

Software developer currently focusing on Android development.