Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

profiler.py:ProfilerWSGIMiddleware:__call__ is not threadsafe #78

Open
holte opened this issue Nov 20, 2015 · 1 comment
Open

profiler.py:ProfilerWSGIMiddleware:__call__ is not threadsafe #78

holte opened this issue Nov 20, 2015 · 1 comment

Comments

@holte
Copy link

holte commented Nov 20, 2015

This method seems to have a race condition that eventually leads to max recursion depth exceeded errors:

The code has the following pattern:

old_memcache_add = memcache.add
memcache.add = (lambda ... : ... old_memcache_add)
...
memcache.add = old_memcache_add

If this is executed by two threads in a particular order it leaves memcache.add in the wrong state, e.g.:

Thread 1: old_memcache_add = memcache.add [1.old_memcache_add = MA]
Thread 1: memcache.add = (lambda ... : ... old_memcache_add) [ memcache.add = L(MA)]
Thread 2: old_memcache_add = memcache.add [2.old_memcache_add = L(MA)]
Thread 2: memcache.add = (lambda ... : ... old_memcache_add) [ memcache.add = L(L(MA))]
Thread 1: memcache.add = old_memcache_add [ memcache.add = MA]
Thread 2: memcache.add = old_memcache_add [ memcache.add = L(MA)]

@benjaminjkraft
Copy link
Contributor

Thanks for the report! This does seem like a potential issue. At the moment I don't think we at KA use the mini-profiler much in multithreaded contexts so this won't be high-priority for us to fix, but if it affects others I'd be happy to accept a pull request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants