Threadgroup: bug concerning the wait/stop methods
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
oslo-incubator |
Fix Released
|
Undecided
|
Jason Dunsmore |
Bug Description
The wait method does not always wait for all the (green)threads to be processed and the stop method does not always stop all threads.
Reason: in the method we iterate over the self.threads list. The problem is that this list can potentially be concurrently edited by the _thread_done callbacks, that remove some items in the list and thus can fool the iterator in the wait method.
1. Below a basic "test" to reproduce the problem (the reason why I have imbricated threadgroups is that it is the only way I managed to reproduce the issue. Statistically, I had to wait for around one minute to see the issue happen: END STUFF printed after the WAIT STUFF things).
2. Attached a correction proposal: one line in the ThreadGroup.
In a thread environment, I'm not even sure this would really fix the bug: indeed, if the shallow copy itself was not thread-safe, we would have to synchronize the _thread_done callbacks with the copy.
In a green thread environment, I may be wrong, but I think the shallow copy fixes the issue: we are saved by the fact that there won't be any greenthread switching during the shallow copy (no IO, nor explicit greenthread switching method called). The copy is thus greenthread safe
#######
#TEST
#######
#!/usr/bin/env python
import eventlet
eventlet.
import random
from openstack.common import threadgroup
class A(object):
def __init__(self):
self.tg = threadgroup.
def test1(self, i):
print "END TEST %s" % i
def run_test(self):
while True:
print "#"*100
# threads = []
for i in range(0,100):
# threads.
# for thd in threads:
# thd.wait()
print "WAIT SELF TG"
if __name__ == '__main__':
a = A()
tg = threadgroup.
tg.
tg.wait()
description: | updated |
description: | updated |
description: | updated |
Changed in oslo: | |
status: | New → Confirmed |
Changed in oslo: | |
assignee: | nobody → Bertrand Lallau (bertrand-lallau) |
Changed in oslo: | |
milestone: | none → icehouse-2 |
Changed in oslo: | |
status: | Fix Committed → Fix Released |
Changed in oslo: | |
milestone: | icehouse-2 → 2014.1 |
Fix proposed to branch: master /review. openstack. org/60096
Review: https:/