You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Story:
We have default gc metrics, for example python_gc_collected_objects_count.
Someone tries to get metrics value(for example http handler). This leads to MutexValue.get() call. Lock is aquired inside get() method.
If garbage collector decides to run at this moment, the callback updating gc metrics is triggered. Inside this callback metrics is need to be updated, but it cant get the lock which is already taken. Deadlock.
Snippet reproducing this story: (if you try to open localhost:8000 it will fail).
importgcimporttimefromthreadingimportLockfromprometheus_clientimportvaluesfromprometheus_clientimportstart_http_serverclassMutexValue(object):
'''A float protected by a mutex.'''_multiprocess=Falsedef__init__(self, typ, metric_name, name, labelnames, labelvalues, **kwargs):
self._value=0.0self._lock=Lock()
definc(self, amount):
withself._lock:
self._value+=amountdefset(self, value):
withself._lock:
self._value=valuedefget(self):
withself._lock:
gc.collect() #<------------------------------ Added only this linereturnself._valuevalues.ValueClass=MutexValuestart_http_server(8000)
whileTrue:
time.sleep(1)
Okay, I see what's happening. As this isn't the first issue in this area, how the GC collector works should probably be reconsidered so that we're not using the client library on the critical path.
Activity
brian-brazil commentedon Jan 4, 2019
What version are you using? This should already be fixed.
megabotan commentedon Jan 4, 2019
prometheus-client==0.5.0
brian-brazil commentedon Jan 4, 2019
Okay, I see what's happening. As this isn't the first issue in this area, how the GC collector works should probably be reconsidered so that we're not using the client library on the critical path.
mhoyer commentedon Feb 8, 2019
We experience the same in our application. Is there any workaround or fix in sight?
brian-brazil commentedon Feb 8, 2019
KeNaCo commentedon Feb 9, 2019
Our mitigation of this problem is simply wrapping call with timeout which kill thread. Sufficient enough to keep ThreadPool working..