ThreadGroup.stop() doesn't always stop threads
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
oslo-incubator |
Fix Released
|
High
|
Zane Bitter | ||
Grizzly |
Fix Released
|
High
|
Zane Bitter |
Bug Description
When attempting to stop running threads in a ThreadGroup via ThreadGroup.stop(), there is a problem because Thread.stop() uses greenthread.kill(), which doesn't really kill anything or prevent the greenthread being rescheduled, it just makes the greenthread raise a greenlet.
This causes a problem if you happen to be in a try/except block which is not fully qualified (e.g it's either naked, or catches a generic Exception). In this instance, the thread does not exit, because the GreenletExit exception is caught, so you maybe see an error logged but then the thread will continue to run.
This can obviously cause very unexpected things to happen if you're expecting the threads in the ThreadGroup to have all been killed and they suddenly start running again... :(
Obviously the real problem here is eventlet, but raising this bug anyway so we can track the problem, and hopefully figure out a workaround.
The only solution I can see at the moment is to ensure every single try/except block in the code-path of the greenthread is fully-qualified, or that the except block contains logic to raise when a GreenletExit is detected. Obviously this is far from ideal, as there are a very large number of generic "except Exception" blocks in the various openstack projects.
I've attached a simple reproducer demonstrating the problem.
Changed in oslo: | |
importance: | Wishlist → High |
milestone: | none → grizzly-3 |
Changed in oslo: | |
status: | Fix Committed → Fix Released |
Thanks Steven. Marking as Wishlist since you seem pretty confident there isn't an obvious fix