Skip to content
Permalink
Browse files

Fix a stack in the daemon_status handler codepath

DAEMON_STATUS change during iteration.
Use a threading RLock to protect that structure.
  • Loading branch information...
cvaroqui committed Jul 15, 2019
1 parent 2b04628 commit f239b3400beb8da166f50ad02a587517acffa21f
Showing with 10 additions and 8 deletions.
  1. +1 −2 lib/osvcd_lsnr.py
  2. +9 −6 lib/osvcd_shared.py
@@ -2,7 +2,6 @@
Listener Thread
"""
import base64
import copy
import json
import os
import sys
@@ -1820,7 +1819,7 @@ def action_daemon_status(self, nodename, **kwargs):
Return a hash indexed by thead id, containing the status data
structure of each thread.
"""
data = copy.deepcopy(self.daemon_status())
data = self.daemon_status()
if self.usr is False or "root" in self.usr_grants:
return data
namespaces = self.usr_grants.get("guest", [])
@@ -29,6 +29,7 @@

# daemon_status cache
LAST_DAEMON_STATUS = {}
DAEMON_STATUS_LOCK = threading.RLock()
DAEMON_STATUS = {}
PATCH_ID = 0

@@ -1380,11 +1381,12 @@ def update_daemon_status(self):
global EVENT_Q
global PATCH_ID
LAST_DAEMON_STATUS = json.loads(json.dumps(DAEMON_STATUS))
DAEMON_STATUS = self._daemon_status()
diff = json_delta.diff(
LAST_DAEMON_STATUS, DAEMON_STATUS,
verbose=False, array_align=False, compare_lengths=False
)
with DAEMON_STATUS_LOCK:
DAEMON_STATUS = self._daemon_status()
diff = json_delta.diff(
LAST_DAEMON_STATUS, DAEMON_STATUS,
verbose=False, array_align=False, compare_lengths=False
)
if not diff:
return
PATCH_ID += 1
@@ -1396,7 +1398,8 @@ def update_daemon_status(self):
})

def daemon_status(self):
return DAEMON_STATUS
with DAEMON_STATUS_LOCK:
return DAEMON_STATUS

@staticmethod
def filter_daemon_status(data, namespaces):

0 comments on commit f239b34

Please sign in to comment.
You can’t perform that action at this time.