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

Add check if childs are still alive and shutdown instead of hanging #1177

Merged
merged 3 commits into from
Sep 30, 2021

Conversation

humrochagf
Copy link
Contributor

Fix: #1115

Since server closes with sys.exit(1) on child process without communicating with the parent supervisor we need to check if the process is still alive.

I used the same interval as the one already setup for the reloader, but it could be another one as well.

Also added the tests for the direct call from the command line, and also ensured sockets are closed at the end of the shutdown. Since child dies before being able to properly close their sockets.

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.

@humrochagf Thanks for the PR! 🎉

First, sorry for taking so long to review this.

Now, I do think the "reload" part makes sense, and we should get that merged. I've added a single comment on it (that I can change it myself).

As for the "multiprocess" part, looks fine as well. Just a remark about the reload_delay, as I don't think it should be used here. But... Although it looks fine, I don't want to merge this part, because I'm working on a process manager for uvicorn (which will be located on the Multiprocess class).

For the reason stated in the previous paragraph, would you mind removing the logic around the Multiprocess, so we can merge the "reload" part?

Comment on lines 83 to 84
for _socket in self.sockets:
_socket.close()
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Let's use the same notation as the server.py.

Suggested change
for _socket in self.sockets:
_socket.close()
for sock in self.sockets:
sock.close()

Comment on lines 46 to 48
while not self.should_exit.wait(self.config.reload_delay):
if not any(p.exitcode is None for p in self.processes):
break
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 used the same interval as the one already setup for the reloader, but it could be another one as well.

Yep, I don't think we should use self.config.reload_delay here.

@Kludex Kludex added this to the Version 0.16.0 milestone Sep 29, 2021
@Kludex Kludex mentioned this pull request Sep 29, 2021
@humrochagf
Copy link
Contributor Author

@humrochagf Thanks for the PR! tada

First, sorry for taking so long to review this.

Now, I do think the "reload" part makes sense, and we should get that merged. I've added a single comment on it (that I can change it myself).

As for the "multiprocess" part, looks fine as well. Just a remark about the reload_delay, as I don't think it should be used here. But... Although it looks fine, I don't want to merge this part, because I'm working on a process manager for uvicorn (which will be located on the Multiprocess class).

For the reason stated in the previous paragraph, would you mind removing the logic around the Multiprocess, so we can merge the "reload" part?

Hey, @Kludex no worries for the delay, and I don't mind removing the multiprocessing part, I agree with you, having a process manager would be much better 😃

I'll do the changes.

@Kludex
Copy link
Sponsor Member

Kludex commented Sep 29, 2021

Thanks! ✨

@humrochagf
Copy link
Contributor Author

Done 🚀

@Kludex Kludex merged commit a9993bd into encode:master Sep 30, 2021
Kludex pushed a commit that referenced this pull request Nov 17, 2021
…1177)

* Add check if childs are still alive and shutdown instead of hanging

* Revert multiprocessing change

* Fix socket loop notation to keep consistency with server.py
Kludex pushed a commit to sephioh/uvicorn that referenced this pull request Oct 29, 2022
…ncode#1177)

* Add check if childs are still alive and shutdown instead of hanging

* Revert multiprocessing change

* Fix socket loop notation to keep consistency with server.py
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.

[BUG] Exit at startup failure on multiple workers
2 participants