From 6e610f43096e1361ea8a876c27a1a56d8a4f407d Mon Sep 17 00:00:00 2001 From: Rod A Santiago Date: Wed, 14 Dec 2016 17:24:21 -0800 Subject: [PATCH] ensured the shutdown event doesn't get sent until all node delete replies have been sent --- daemon/core/coreserver.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/daemon/core/coreserver.py b/daemon/core/coreserver.py index 7849d069..4d54dc3e 100644 --- a/daemon/core/coreserver.py +++ b/daemon/core/coreserver.py @@ -306,6 +306,7 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler): self.msgq = [] self.msgcv = threading.Condition() self.nodestatusreq = {} + self._shutdownlock = threading.Lock() numthreads = int(server.cfg['numthreads']) if numthreads < 1: raise ValueError, \ @@ -666,16 +667,19 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler): n = self.session.obj(nodenum) except KeyError: pass - self.session.delobj(nodenum) - - if msg.flags & coreapi.CORE_API_STR_FLAG: - tlvdata = "" - tlvdata += coreapi.CoreNodeTlv.pack(coreapi.CORE_TLV_NODE_NUMBER, - nodenum) - flags = coreapi.CORE_API_DEL_FLAG | coreapi.CORE_API_LOC_FLAG - replies.append(coreapi.CoreNodeMessage.pack(flags, tlvdata)) - for reply in self.session.checkshutdown(): - replies.append(reply) + + with self._shutdownlock: + self.session.delobj(nodenum) + + if msg.flags & coreapi.CORE_API_STR_FLAG: + tlvdata = "" + tlvdata += coreapi.CoreNodeTlv.pack(coreapi.CORE_TLV_NODE_NUMBER, + nodenum) + flags = coreapi.CORE_API_DEL_FLAG | coreapi.CORE_API_LOC_FLAG + replies.append(coreapi.CoreNodeMessage.pack(flags, tlvdata)) + + for reply in self.session.checkshutdown(): + replies.append(reply) # Node modify message (no add/del flag) else: n = None