-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resolving hostnames for bind #1719
Comments
Thank you for reporting this issue! If you would like to make a PR, I'd be happy to review it with you. |
It seems like we might have to change that first comprehension to complex comprehension and have |
Tried to make a nicer approach to handle different family types there https://github.com/wanneut/gunicorn |
@wanneut I took a look and left some style comments, but I like your approach! I won't be able to look at tests until later today, but this is great. Thank you. You should be able to close sockets with |
We also have a helper in |
I start adopting the tests. |
I've stumbled upon exact this problem and see that the old PR was abandoned. I've created a minimal change which allows gunicorn to listen on IPv6 addresses specified as hostnames. Unfortunately the GitHub check on AppVeyor seems to be broken currently. Not sure how I could proceed with this #2689, @tilgovi maybe you can advise? |
I've run the tests locally and they seem to pass (apart from pylint, although it's not something broken by this PR) |
gunicorn takes a list of hostnames, checks for everyone if it is a IPv6 address and if it is not, it binds to the IPv4 address of the hostname.
The relevant parts are:
gunicorn/gunicorn/config.py
Line 125 in d1f5268
gunicorn/gunicorn/sock.py
Line 132 in d1f5268
gunicorn/gunicorn/util.py
Line 227 in d1f5268
This makes two wrong assumptions:
Even for the most common example localhost this assumptions are not true:
localhost resolves on the most systems to ::1 and 127.0.0.1. But gunicorn binds only to 127.0.0.1 (the first IPv4 address)
If a standards-compliant software tries to connect to gunicorn on localhost it will at first try to connect to ::1 and only after that times out to 127.0.0.1.
So most of my clients disable IPv6 to make gunicorn react faster…
A much better approach would be to loop over all results of getaddrinfo and just bind to whatever family it returns:
https://docs.python.org/2.5/lib/socket-example.html
The text was updated successfully, but these errors were encountered: