Skip to content

Conversation

@edmorley
Copy link
Member

@edmorley edmorley commented Nov 20, 2024

By default when the PORT env var is set, gunicorn binds to the IPv4 interface 0.0.0.0:$PORT:
https://docs.gunicorn.org/en/stable/settings.html#bind

Now, we configure it to bind to the IPv6 interface [::]:$PORT instead, allowing the app to work in IPv6-only environments.

We don't have it bind to both the IPv4 and IPv6 interfaces, since otherwise on Linux by default gunicorn would fail to boot with:

[ERROR] connection to ('::', 5006) failed: [Errno 98] Address already in use

...and when binding to the IPv6 interface IPv4 connections will still work (so long as IPV6_V6ONLY hasn't been enabled).

If this strategy causes issues, we could always start using the reuse_port option, however, that makes the DX worse for the local development use-case (it's then possible to leave a stale gunicorn process running, which will serve requests and give the impression code changes aren't taking effect).

I've added a gunicorn.conf.py config file rather than passing CLI args to the gunicorn command, since it allows for more flexibility with the configuration (and there are other settings we'll be adding soon). See:
https://docs.gunicorn.org/en/stable/configure.html

GUS-W-17280180.

By default when the `PORT` env var is set, gunicorn binds to
the IPv4 interface (`'0.0.0.0:$PORT'`).

Now, we configure it to bind to the IPv6 interface instead,
allowing the app to work in IPv6-only environments.

We don't have it bind to both the IPv4 and IPv6 interfaces, since
otherwise on Linux by default gunicorn would fail to boot with:

```
[ERROR] connection to ('::', 5006) failed: [Errno 98] Address already in use
```

...and when binding to the IPv6 interface IPv4 connections will
still work (so long as `IPV6_V6ONLY` hasn't been enabled).

If this strategy causes issues, we could always start using the
`reuse_port` option, however, that makes the DX worse for
the local development use-case (it's then possible to leave a
stale gunicorn process running, which will serve requests
and give the impression code changes aren't taking effect).

I've added a `gunicorn.conf.py` config file rather than passing CLI
args to the `gunicorn` command, since it allows for more flexibility
with the configuration (and there are other settings we'll be adding
soon).

See:
https://docs.gunicorn.org/en/stable/settings.html#bind
https://docs.gunicorn.org/en/stable/configure.html

GUS-W-17280180.
@edmorley edmorley self-assigned this Nov 20, 2024
@heroku heroku bot temporarily deployed to getting-star-edmorley-i-2caler November 20, 2024 17:07 Inactive
@edmorley edmorley marked this pull request as ready for review November 20, 2024 17:41
@edmorley edmorley requested a review from a team as a code owner November 20, 2024 17:41
@edmorley edmorley removed the request for review from a team November 20, 2024 17:41
@edmorley edmorley merged commit 962e798 into main Nov 20, 2024
1 check passed
@edmorley edmorley deleted the edmorley/ipv6 branch November 20, 2024 17:54
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.

1 participant