-
-
Notifications
You must be signed in to change notification settings - Fork 735
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
Fix server not running with explicit hostname #827
Conversation
uvicorn/config.py
Outdated
@@ -122,7 +122,7 @@ class _IPKind(Enum): | |||
|
|||
|
|||
def _get_server_start_message( | |||
host_ip_version: _IPKind = _IPKind.IPv4, | |||
host_ip_version: Optional[_IPKind] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@euri10
Looks like I was wrong proposing _IPKind
enum in #803 . Looks like this function has 2 modes: either "to get a message for ipv6" and "to get a message for ipv4/hostname"
What do you think if we delete the _IPKind
enum and change this function signature to
host_ip_version: Optional[_IPKind] = None, | |
*, is_ipv6_message: bool = False |
(and also change the function body & usage)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup good idea, I didnt see it coming either 🍔
else: | ||
message, color_message = _get_server_start_message(_IPKind.IPv4) | ||
try: | ||
addr = ip_address(config.host) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you cannot omit this try-except block (or to replace it by regex)
Another approach to check if it's an ip or hostname is to:
socket.getaddrinfo(config.host, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST)
But it's also should be wrapped by try-except statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, nice fix
For traceability: marking this as a cleanup of #803. |
This reverts commit d78394e.
* Revert "Fix server not running with explicit hostname (#827)" This reverts commit d78394e. * Revert "Fix reload with ipv6 host (#803)" This reverts commit 5acaee5. * Rework IPv6 support * Fix IPv6 localhost equivalent Co-authored-by: euri10 <[email protected]> * Reduce diff size * More diff size reduction * Fix: self.host -> config.host Co-authored-by: euri10 <[email protected]>
Fixes #825
I'm not super happy with the try catch on the ip adresss but couldn't think of something else, so if someone has a better idea please share !
Not happy because I'm not sure it accounts for all potential use cases,