Skip to content

fix: only bind to Unix socket on Heroku with nginx buildpack#2642

Open
mroderick wants to merge 1 commit into
masterfrom
fix/puma-socket-dev-binding
Open

fix: only bind to Unix socket on Heroku with nginx buildpack#2642
mroderick wants to merge 1 commit into
masterfrom
fix/puma-socket-dev-binding

Conversation

@mroderick

@mroderick mroderick commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Problem

config/puma.rb was checking for the presence of config/nginx.conf.erb to decide whether to bind to a Unix socket or a TCP port. Since the nginx config file is committed to the repository, this check evaluated to true in all environments — including development — causing Puma to bind to unix:///tmp/nginx.socket instead of a TCP port.

This meant that running bundle exec rails server in development would listen on a Unix socket that is not accessible via a browser, breaking the local development workflow.

Root cause

The condition was introduced in PR #2629 to support the heroku-community/nginx buildpack, which uses bin/start-nginx to launch nginx alongside Puma. The socket and /tmp/app-initialized signal are only meaningful when that buildpack orchestrates the boot. However, checking File.exist?("config/nginx.conf.erb") as a proxy for "running under nginx" is unreliable because the file exists in development, CI, and everywhere the repo is cloned.

Fix

Add a check for ENV["DYNO"] before the socket binding. Heroku sets this variable on all dynos, making it a reliable signal that the nginx buildpack is actually in use.

# Before
if File.exist?("config/nginx.conf.erb")

# After
if ENV["DYNO"] && File.exist?("config/nginx.conf.erb")

This preserves the nginx buildpack integration on Heroku while restoring the default TCP port binding in development and other non-Heroku environments.

Verification

  • bundle exec rails server in development binds to http://localhost:3000
  • Heroku deployment still works with the nginx buildpack

@mroderick mroderick marked this pull request as ready for review June 12, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants