daemon: adjustments for shutdown behavior to avoid issues when shutting down, when already shutdown for the various different cases, but to also make sure the pycore directory is removed
This commit is contained in:
parent
b195891b3b
commit
0306f77147
3 changed files with 9 additions and 34 deletions
|
@ -315,10 +315,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
logging.debug("stop session: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
session.data_collect()
|
||||
session.set_state(EventTypes.DATACOLLECT_STATE, send_event=True)
|
||||
session.clear()
|
||||
session.set_state(EventTypes.SHUTDOWN_STATE, send_event=True)
|
||||
session.shutdown()
|
||||
return core_pb2.StopSessionResponse(result=True)
|
||||
|
||||
def CreateSession(
|
||||
|
|
|
@ -735,6 +735,11 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
elif message.flags & MessageFlags.DELETE.value:
|
||||
with self._shutdown_lock:
|
||||
result = self.session.delete_node(node_id)
|
||||
if result and self.session.get_node_count() == 0:
|
||||
self.session.set_state(EventTypes.SHUTDOWN_STATE)
|
||||
self.session.delete_nodes()
|
||||
self.session.distributed.shutdown()
|
||||
self.session.sdt.shutdown()
|
||||
|
||||
# if we deleted a node broadcast out its removal
|
||||
if result and message.flags & MessageFlags.STRING.value:
|
||||
|
|
|
@ -756,23 +756,18 @@ class Session:
|
|||
"""
|
||||
Shutdown all session nodes and remove the session directory.
|
||||
"""
|
||||
if self.state == EventTypes.SHUTDOWN_STATE:
|
||||
return
|
||||
logging.info("session(%s) state(%s) shutting down", self.id, self.state)
|
||||
self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True)
|
||||
self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True)
|
||||
|
||||
if self.state != EventTypes.SHUTDOWN_STATE:
|
||||
self.set_state(EventTypes.DATACOLLECT_STATE, send_event=True)
|
||||
self.set_state(EventTypes.SHUTDOWN_STATE, send_event=True)
|
||||
# clear out current core session
|
||||
self.clear()
|
||||
|
||||
# shutdown sdt
|
||||
self.sdt.shutdown()
|
||||
|
||||
# remove this sessions working directory
|
||||
preserve = self.options.get_config("preservedir") == "1"
|
||||
if not preserve:
|
||||
shutil.rmtree(self.session_dir, ignore_errors=True)
|
||||
|
||||
# call session shutdown handlers
|
||||
for handler in self.shutdown_handlers:
|
||||
handler(self)
|
||||
|
@ -1116,7 +1111,6 @@ class Session:
|
|||
if node:
|
||||
node.shutdown()
|
||||
self.sdt.delete_node(_id)
|
||||
self.check_shutdown()
|
||||
return node is not None
|
||||
|
||||
def delete_nodes(self) -> None:
|
||||
|
@ -1279,27 +1273,6 @@ class Session:
|
|||
self.add_remove_control_net(2, remove=True)
|
||||
self.add_remove_control_net(3, remove=True)
|
||||
|
||||
def check_shutdown(self) -> bool:
|
||||
"""
|
||||
Check if we have entered the shutdown state, when no running nodes
|
||||
and links remain.
|
||||
|
||||
:return: True if should shutdown, False otherwise
|
||||
"""
|
||||
node_count = self.get_node_count()
|
||||
logging.debug(
|
||||
"session(%s) checking shutdown: %s nodes remaining", self.id, node_count
|
||||
)
|
||||
shutdown = False
|
||||
if node_count == 0:
|
||||
shutdown = True
|
||||
# shutting down and clearing data for legacy gui
|
||||
self.set_state(EventTypes.SHUTDOWN_STATE)
|
||||
self.delete_nodes()
|
||||
self.distributed.shutdown()
|
||||
self.sdt.shutdown()
|
||||
return shutdown
|
||||
|
||||
def short_session_id(self) -> str:
|
||||
"""
|
||||
Return a shorter version of the session ID, appropriate for
|
||||
|
|
Loading…
Reference in a new issue