Skip to content
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

Merged
merged 3 commits into from
Oct 22, 2020

Conversation

euri10
Copy link
Member

@euri10 euri10 commented Oct 21, 2020

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,

@@ -122,7 +122,7 @@ class _IPKind(Enum):


def _get_server_start_message(
host_ip_version: _IPKind = _IPKind.IPv4,
host_ip_version: Optional[_IPKind] = None,
Copy link
Member

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

Suggested change
host_ip_version: Optional[_IPKind] = None,
*, is_ipv6_message: bool = False

(and also change the function body & usage)

Copy link
Member Author

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)
Copy link
Member

@cdeler cdeler Oct 21, 2020

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

@euri10 euri10 requested a review from cdeler October 21, 2020 16:44
Copy link
Member

@cdeler cdeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, nice fix :octocat:

@florimondmanca
Copy link
Member

For traceability: marking this as a cleanup of #803.

florimondmanca added a commit that referenced this pull request Oct 24, 2020
florimondmanca added a commit that referenced this pull request Nov 8, 2020
* 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]>
@euri10 euri10 mentioned this pull request Nov 22, 2020
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.

Uvicorn fails to resolve host names in version 0.12.2
3 participants