Browse Source

Fix possible race condition

Reviewed as #400

git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@3488 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
42fd38b8bc
1 changed files with 9 additions and 2 deletions
  1. 9 2
      src/bin/zonemgr/zonemgr.py.in

+ 9 - 2
src/bin/zonemgr/zonemgr.py.in

@@ -324,8 +324,14 @@ class ZonemgrRefresh:
         return False
         return False
 
 
     def _run_timer(self, start_event):
     def _run_timer(self, start_event):
-        start_event.set()
         while self._running:
         while self._running:
+            # Notify run_timer that we already started and are inside the loop.
+            # It is set only once, but when it was outside the loop, there was
+            # a race condition and _running was could be set false before we
+            # could enter it
+            if start_event:
+                start_event.set()
+                start_event = None
             # If zonemgr has no zone, set timer timeout to self._lowerbound_retry.
             # If zonemgr has no zone, set timer timeout to self._lowerbound_retry.
             if self._zone_mgr_is_empty():
             if self._zone_mgr_is_empty():
                 timeout = self._lowerbound_retry
                 timeout = self._lowerbound_retry
@@ -354,7 +360,8 @@ class ZonemgrRefresh:
             for fd in rlist:
             for fd in rlist:
                 if fd == self._read_sock: # awaken by shutdown socket
                 if fd == self._read_sock: # awaken by shutdown socket
                     # self._running will be False by now, if it is not a false
                     # self._running will be False by now, if it is not a false
-                    # alarm
+                    # alarm (linux kernel is said to trigger spurious wakeup
+                    # on a filehandle that is not really readable).
                     continue
                     continue
                 if fd == self._check_sock: # awaken by check socket
                 if fd == self._check_sock: # awaken by check socket
                     self._check_sock.recv(32)
                     self._check_sock.recv(32)