Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appengine Appstats giving deadlock

i have a Flask app on gae, it is working correctly. I am trying to add Appstats support, but once i enable it, i have a deadlock.

This deadlock is apparently happening when i try to setup a werkzeug LocalProxy with the logged user ndb model (it is called current_user, like it's done in Flask-Login, to give you more details).

The error is:

RuntimeError: Deadlock waiting for <Future 104c02f50 created by get_async(key.py:545) for tasklet get(context.py:612) suspended generator get(context.py:645); pending>

The LocalProxy object is setup using this syntax (as per Werkzeug doc):

current_user = LocalProxy(lambda: _get_user())

And _get_user() makes a simple synchronous query ndb.query.

Thanks in advance for any help.

like image 329
Bruno Ripa Avatar asked Apr 27 '26 12:04

Bruno Ripa


1 Answers

I ran into this issue today. In my case it seems to be that the request to get a users details is triggering appstats. Appstats is then going through the call stack and storing details of all the local variables in each stack frame.

The session itself is in one of these stack frames, so appstats tries to print it out and triggers the user fetching code again.

Came up with 2 "solutions", though neither of them are great.

  • Disable appstats altogether.
  • Disable logging of local variables in appstats.

I've gone for the latter at the moment. appstats allows you to configure various settings in your appengine_config.py file. I was able to avoid logging of local variable details (which stops the code from triggering the bug) by adding this:

appstats_MAX_LOCALS = 0
like image 95
obmarg Avatar answered Apr 29 '26 04:04

obmarg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!