client_python icon indicating copy to clipboard operation
client_python copied to clipboard

Use re-entrant lock.

Open btimby opened this issue 1 year ago • 1 comments

While using django-prometheus I found a situation where adding a metric to the registry caused a read from cache. I had cache metrics enabled, which attempted to add cache metrics to the registry. This resulting in a deadlock as the second registry call attempted to obtain the lock already held lower on the call stack.

I changed usage to an RLock, which allows the lock to be obtained in a nested fashion within a call stack. This still provides thread safety.

btimby avatar Mar 05 '24 17:03 btimby

@csmarchbanks Only one test needed to check the status of the lock. Therefore, I simply switched all locks to RLock and added a utility function (in the test file) for that test.

btimby avatar Aug 02 '24 17:08 btimby

@csmarchbanks Thanks! I was not sure what to do and have not had a chance to research it.

btimby avatar Sep 17 '24 20:09 btimby