-
-
Notifications
You must be signed in to change notification settings - Fork 782
Stop hang when use mongo SSL #5240
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d974873
Stop hang when use mongo SSL
amanda11 c1a0296
Fix black
amanda11 ceefe7a
Update CHANGELOG.rst
amanda11 b287836
Merge branch 'master' into monkey_patch_st2stream
amanda11 ae326c9
Update wsgi.py
Kami b4027f3
Merge branch 'master' into monkey_patch_st2stream
Kami 58e543f
Merge branch 'master' of github.com:StackStorm/st2 into monkey_patch_…
Kami 2a71ff0
Remove testing change, also run micro benchmarks under 3.8.
Kami 67b0051
Merge branch 'master' into monkey_patch_st2stream
Kami 3df9f4d
Merge branch 'monkey_patch_st2stream' of github.com:StackStorm/st2 in…
Kami File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm somewhat worried if that is the correct / right change - I know that in the past we intentionally only did monkey patching in the worker and not the parent process.
I guess technically if all the tests pass and we observe no weird behavior locally with CTRL+C and stopping gunicorn process, it's probably.
But having said that, I believe we do exactly the same thing for st2api and st2auth - and if we do, we should likely update all the affected places.
Uh oh!
There was an error while loading. Please reload this page.
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.
Btw, which version of st2 + mongoengine + pymongo are you using?
That hanging looks exactly the same as the hanging PR which adds support for Python 3.8 + Mongo DB 4.4 uncovered which I believe I tracked to us not performing monkey patching early enough so pymongo obtains reference to non patched version of threading module which will cause all kinds of issues.
And from the symptoms you mentioned it indeed looks like it could be related to the same root cause (although in that case it's related to threading module and here it's likely related to ssl one).
Uh oh!
There was an error while loading. Please reload this page.
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.
This was StackStorm 3.4.1 on EL8. Mongo 4.0 and python 3.6.
st2api, st2auth were connecting successfully but st2stream wasn't. (So applied same change that was made to st2api to st2stream).
st2stream seems to be the only one that monkey patches differently to the other gunicorn processes. Was there a reason for that?
So st2api and st2auth both monkey patch in wsgi.py and have removed the line to monkey patch in app.py. But st2stream was the odd one out.
Uh oh!
There was an error while loading. Please reload this page.
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.
Problem might be fixed already in 3.5dev. Putting back to draft whilst investigate further.
Upgraded a 3.4.1 on CentOS 8 that was having problem to 3.5 dev, and couldn't reproduce - so although this change fixed 3.4.1, might not be required on 3.5dev.
Will look to investigate monkey patch changes in 3.5.dev...
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.
Yeah, st2stream is a bit special since it keeps a long running connections open and IIRC there were issues related to gracefully shutting down the server when performing monkey patching in the main gunicorn process as well.
Having said that - I do think your change is generally correct and right one (we do want to perform monkey patching as early as possible, before importing anything else), but if possible we should verify it doesn't negatively affect the server shutdown logic and / or only do that if we are running in the worker and not the main gunicorn process.
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.
Also, with this logic we will call
monkey_patch()twice in case stream service is started using regular API endpoint and not using gunicorn (st2stream/bin/st2stream), but this likely should not be an issue.Uh oh!
There was an error while loading. Please reload this page.
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.
@Kami It looks like this is fixed by 3.5dev-31 (4922329). This is the minimalist 3.5dev RPM that I can upgrade my 3.4.1 system to, to resolve the problem.
3.5dev-27 (0f8af40) from unstable repo has the problem. So fixed somewhere between those commits (and it's not just the upgrade of eventlet)
So we shouldn't need to patch 3.5. Am trying to track down what the change is that has fixed this and see if can find same fix for 3.4.1. So we don't have to move the monkey patch on 3.5 as the current master branch is ok - to resolve this problem.
So I'm going to suggest closing this PR and not merging... (Though I'd like to find out what fix could be applied to 3.4.1 to fix it...)
Uh oh!
There was an error while loading. Please reload this page.
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.
3.5dev-27 + gunicorn==20.1.0 works.
Will try a 3.4.1 install with gunicorn upgraded to see if that fixes it.
Yeah - 3.4.1 + gunicorn==20.1.0 works.
I might translate this to an issue - so that others know the workaround...
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.
Per my comment above, I still think it would be better if we can try to move monkey patching to as early as possible (before any other imports) - that's the right way to do it.
Doing it later on has no guarantee it will always work and won't break in the feature. Technically, even if some module obtain a reference to a patched module which is patched later on, patching logic will try to replace that module in sys.module, but there is no guarantee that this will always work correctly (depends on how reference to the module is obtained if some hacks are involved and also what's done with the module before it's monkey patched - technically if it's just imported and not used until post monkey patch it should work, but that's not always the case and sometimes imports have side affects).