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

Adapt bind_socket to make it usable with multiple processes #1009

Merged
merged 14 commits into from Jun 21, 2021

Conversation

euri10
Copy link
Member

@euri10 euri10 commented Mar 15, 2021

This makes it possible to use reload and workers flag with uds and fd.

fixes #428 #368 #586 #722

@euri10 euri10 requested a review from Kludex June 7, 2021 13:09
@euri10 euri10 marked this pull request as ready for review June 7, 2021 13:09
@euri10 euri10 marked this pull request as draft June 7, 2021 14:02
@euri10
Copy link
Member Author

euri10 commented Jun 7, 2021

still WIP I noticed the uvicorn logger message needs to be adapted

@euri10 euri10 marked this pull request as ready for review June 8, 2021 13:09
@euri10
Copy link
Member Author

euri10 commented Jun 8, 2021

ready now @Kludex !

Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

I did my best here. It's a short PR, but I feel like I'm not qualified to approve it yet. I'm going to study some details before having the confidence to do so.

But I hope my current comments make sense.

uvicorn/config.py Show resolved Hide resolved
uvicorn/config.py Outdated Show resolved Hide resolved
tests/test_config.py Show resolved Hide resolved
@euri10
Copy link
Member Author

euri10 commented Jun 10, 2021

ready for another review @Kludex
let me know if something not clear I can easily expain

@euri10 euri10 requested a review from Kludex June 10, 2021 09:05
uvicorn/main.py Outdated
Comment on lines 395 to 396
if config.uds:
os.remove(config.uds)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Maybe I'm mistaken, but can't we have a single one of those outside the conditional?

Suggested change
if config.uds:
os.remove(config.uds)
if config.uds:
os.remove(config.uds)

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I guess we can, but it's not right, because we bind inside them. 🤔 Right?

Copy link
Member Author

Choose a reason for hiding this comment

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

it looks simpler yes, I removed occurrences in the basereload and multiprocess shutdown method and put it outside

Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

I'm confident enough now.

But maybe we should wait for the mypy merge first? Anyway, your call.

@euri10
Copy link
Member Author

euri10 commented Jun 10, 2021

But maybe we should wait for the mypy merge first? Anyway, your call.

the one on config.py ?

@Kludex
Copy link
Sponsor Member

Kludex commented Jun 10, 2021

Yeah

@euri10 euri10 added the hold Don't merge yet label Jun 10, 2021
@euri10
Copy link
Member Author

euri10 commented Jun 10, 2021

Yeah

that's a good idea, he put a lot of efforts into it and it would be cruel to have to add that part on top of it ;)

@@ -395,37 +395,63 @@ def setup_event_loop(self) -> None:
loop_setup()

def bind_socket(self) -> socket.socket:
family = socket.AF_INET
addr_format = "%s://%s:%d"
logger_args: List[Union[str, int]]
Copy link
Member Author

Choose a reason for hiding this comment

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

just needed to add this post-merge with master @Kludex
the rest stayed the same

Copy link
Member Author

Choose a reason for hiding this comment

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

So I removed the hold button and feel free to merge if still ok with this !

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I find it so weird that the approval is not removed after a commit is pushed. I don't understand the reason behind it.

Anyway, LGTM! :)

@euri10 euri10 removed the hold Don't merge yet label Jun 21, 2021
@Kludex Kludex merged commit b5af104 into encode:master Jun 21, 2021
@euri10 euri10 deleted the uds_mutliple_workers branch June 22, 2021 04:46
Kludex pushed a commit that referenced this pull request Nov 17, 2021
* Adapt bind_socket to make it usable with multple processes

* Lint

* we are in single proc here

* Remove socket file also in reloader

* Tests

* Tests

* Remove socket on close

* Changed if / else to check uds / fds

* Refactored logging inside bind_socket

* Added test for fd

* Refactored removal of socket

* Minimized diff post merge
Kludex pushed a commit to sephioh/uvicorn that referenced this pull request Oct 29, 2022
)

* Adapt bind_socket to make it usable with multple processes

* Lint

* we are in single proc here

* Remove socket file also in reloader

* Tests

* Tests

* Remove socket on close

* Changed if / else to check uds / fds

* Refactored logging inside bind_socket

* Added test for fd

* Refactored removal of socket

* Minimized diff post merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UNIX domain socket raises 503 when workers are used
2 participants