From e792120446768ebc862db4098de8a802794d7988 Mon Sep 17 00:00:00 2001 From: Mike Graves Date: Tue, 29 Jun 2021 11:39:36 -0400 Subject: [PATCH 1/2] Add exception handler for loop The async loop had no exception handler attached besides the default. This would cause the server to hang when an unhandled exception occurred. --- plugins/module_utils/turbo/server.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/module_utils/turbo/server.py b/plugins/module_utils/turbo/server.py index cacc2a1..c2443d3 100644 --- a/plugins/module_utils/turbo/server.py +++ b/plugins/module_utils/turbo/server.py @@ -241,9 +241,15 @@ async def handle(self, reader, writer): await embedded_module.unload() + def handle_exception(self, loop, context): + e = context.get("exception") + traceback.print_exception(type(e), e, e.__traceback__) + self.stop() + def start(self): self.loop = asyncio.get_event_loop() self.loop.add_signal_handler(signal.SIGTERM, self.stop) + self.loop.set_exception_handler(self.handle_exception) self._watcher = self.loop.create_task(self.ghost_killer()) import sys From 670a9d0a7ab745e7d65d21c3ab1a625c257fd86d Mon Sep 17 00:00:00 2001 From: Mike Graves Date: Tue, 29 Jun 2021 11:46:55 -0400 Subject: [PATCH 2/2] Add changelog fragment --- changelogs/fragments/67-add-exception-handler.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/67-add-exception-handler.yaml diff --git a/changelogs/fragments/67-add-exception-handler.yaml b/changelogs/fragments/67-add-exception-handler.yaml new file mode 100644 index 0000000..8955f2f --- /dev/null +++ b/changelogs/fragments/67-add-exception-handler.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - add exception handler to main async loop (https://github.com/ansible-collections/cloud.common/pull/67).