-
Notifications
You must be signed in to change notification settings - Fork 690
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(python-plugin): update internal interpreter state immediately upon forking #2388
Conversation
uwsgi.h
Outdated
@@ -1039,6 +1039,8 @@ struct uwsgi_plugin { | |||
void *data; | |||
void (*on_load) (void); | |||
int (*init) (void); | |||
void (*pre_uwsgi_fork) (void); |
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.
Can you move it at the end of the structure for maintaining ABI?
core/uwsgi.c
Outdated
@@ -3338,14 +3338,6 @@ int uwsgi_start(void *v_argv) { | |||
} | |||
} | |||
|
|||
// master fixup |
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.
you should leave this part in for not breaking other plugins
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.
@unbit I did not see the master_fixup
hook used elsewhere in the repository but that doesn't mean it's not used by a plugin a user might have, so I can add this back. Are you aware of such a plugin?
core/mule.c
Outdated
@@ -69,12 +69,6 @@ void uwsgi_mule(int id) { | |||
|
|||
uwsgi_close_all_sockets(); | |||
|
|||
for (i = 0; i < 256; i++) { |
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.
you should leave this part in for not breaking other plugins
@majorgreys thanks a lot, my only doubt (in addition to the review comments) is about the old (and ugly, obviously) up.call_osafterfork. Basically it loses any meaning with your patch so i think we can safely remove this (at least in master). For LTS i would probably introduce this new behaviour (albeit definitely correct) as an option. I know it is annoying but LTS grants the user that we do not break/change old stuff (honestly i am not sure about the implications, very probably only app-managed signal management will be affected, and in a positive way). @xrmx any thought? |
b6815df
to
edd4c74
Compare
I've updated the change now to make it so the old behavior can be retained, specifically with regards to Given the needs of LTS, I'm inclined to focus this PR on non-breaking changes so it can be easily backported to the 2.0 branch and open a separate PR for the breaking changes so that they can end up on master. @unbit Does that work for what you had in mind for how to introduce these changes? |
edd4c74
to
3b4dcdd
Compare
👋🏽 @unbit Any update on this PR? I addressed the concerns you raised with regards to merging this into LTS. |
Merged and broke master CI :) |
@xrmx Thanks for the heads up. I'll see if I can reproduce this locally. |
@majorgreys Hello, thanks for fixing the issue, but I was trying the new option
This was discussed here but remains unresolved, can you help to see if it is my env problem or something else? Really appreciated. |
@Superskyyy I need to still review the linked issue but I can confirm that I can reproduce this error. I don't see it when #2179 also reported the same exception when Code for minimal reproduction: https://gist.github.com/majorgreys/3ee1716b107ad80226b12145ae87276a |
Fixes #2387
This PR adds
pre_uwsgi_fork
andpost_uwsgi_fork
hooks touwsgi_plugin
in order to update the internal interpreter state of CPython immediately before and immediately after the call touwsgi_fork
. This follows the implementation of the standard libraryos.fork()
in CPython.While these two hooks effectively replace existing code to update the internal interpreter state during the lifecycle of master and worker processes, we preserve the current behavior for uWSGI LTS. We instead provide a new option
py-call-uwsgi-fork-hooks
to enable the new feature.We add test coverage for the issue of deadlocked workers raised in #2387 parameterized for relevant configurations options.