Browse Source

Fix stop of loopingcall

Patch [1] for switched to use eventlet Event for loopingcall events.

It may now happen that stop event is sent when other event was
already sent and loopingcall is already not running.
That cause AssertionError in eventlet.event module.

To avoid that, we should check if if loopingcall is
running before sending _abort.set().

[1] https://review.openstack.org/#/c/611807/

Closes-Bug #1800879

Change-Id: I28ad3bdb51a20350c90dee4420058c30946897e5
Slawek Kaplonski 5 months ago
parent
commit
3e08f3375e
2 changed files with 12 additions and 1 deletions
  1. 2
    1
      oslo_service/loopingcall.py
  2. 10
    0
      oslo_service/tests/test_loopingcall.py

+ 2
- 1
oslo_service/loopingcall.py View File

@@ -121,7 +121,8 @@ class LoopingCallBase(object):
121 121
         return not self._abort.is_set()
122 122
 
123 123
     def stop(self):
124
-        self._abort.set()
124
+        if self._running:
125
+            self._abort.set()
125 126
 
126 127
     def wait(self):
127 128
         return self.done.wait()

+ 10
- 0
oslo_service/tests/test_loopingcall.py View File

@@ -100,6 +100,16 @@ class LoopingCallTestCase(test_base.BaseTestCase):
100 100
         wait_ev.set()
101 101
         timer.wait()
102 102
 
103
+    def test_no_double_stop(self):
104
+        def _raise_it():
105
+            raise loopingcall.LoopingCallDone(False)
106
+
107
+        timer = loopingcall.FixedIntervalLoopingCall(_raise_it)
108
+        timer.start(interval=0.5)
109
+
110
+        timer.stop()
111
+        timer.stop()
112
+
103 113
     def test_repeat(self):
104 114
         self.num_runs = 2
105 115
 

Loading…
Cancel
Save