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

kr8s and gevent (wsgi) #481

Open
teocns opened this issue Aug 27, 2024 · 4 comments
Open

kr8s and gevent (wsgi) #481

teocns opened this issue Aug 27, 2024 · 4 comments
Labels
bug Something isn't working kr8s needs info Needs more information sync/async Related to sync/async support

Comments

@teocns
Copy link

teocns commented Aug 27, 2024

Which project are you reporting a bug for?

kr8s

What happened?

When I was just about to celebrate testing a flask app in production.... kr8s took it away from me 🤣

So it turns out it doesn't play well with wsgi. From my analysis it's merely due to the async keyword-statements which gevent hallucinates on top of, as it runs its own internal monkey patching on python's threading system library

As a temporary fix, I'm now running a sync-native fork.

Looking for ideas and brainstorming onto ways we can merge this, if it's the case

Anything else?

fastapi/fastapi#6395

@teocns teocns added the bug Something isn't working label Aug 27, 2024
@jacobtomlinson
Copy link
Member

jacobtomlinson commented Aug 27, 2024

I think I would agree with the comment by tiangolo fastapi/fastapi#6395 (comment). If gevent is doing some monkey patching of Python internals then we can't guarantee that it will work. It sounds like nobody should be using gevent 😅.

That being said I'd be interested to understand more about what is going wrong. If you can share some small examples of how to reproduce the issues you are seeing I can dig in and see if there are any small things we can change to get things to play nicely.

Out of interest if creating a sync-native fork is your current workaround why not use a sync-native library like kubernetes or pykube-ng? I'm mainly asking because I'm excited that you seem to like kr8s enough to perservere here.

@jacobtomlinson jacobtomlinson added kr8s sync/async Related to sync/async support labels Aug 27, 2024
@teocns
Copy link
Author

teocns commented Aug 27, 2024

I'm mainly asking because I'm excited that you seem to like kr8s enough to perservere here.

That answers it partially 💯 on the other hand my backend's implementation is already founded around kr8s' APIObject, serialization and lookup features - would've taken me longer to adopt a different API than quickly refactoring async-to-sync.

If you can share some small examples of how to reproduce the issues you are seeing I can dig in and see if there are any small things we can change to get things to play nicely.

I think this is easy to reproduce: setup flask w/ gevent, and the issue happens exactly when invoking asgiref.async_to_sync, which flask[async] uses in current_app.ensure_sync. You will see a bunch of nasty runtime errors coming out of the threading module...

It sounds like nobody should be using gevent 😅.

I'm in grief

@jacobtomlinson
Copy link
Member

Could you share a step by step that I can copy and paste, I'm not familiar with gevent and flask[async].

https://matthewrocklin.com/minimal-bug-reports

@teocns
Copy link
Author

teocns commented Aug 28, 2024

I'll be happy to, give me a few days and I'll setup a branch for us 👍

@jacobtomlinson jacobtomlinson added the needs info Needs more information label Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working kr8s needs info Needs more information sync/async Related to sync/async support
Projects
None yet
Development

No branches or pull requests

2 participants