]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: processes_watchdog: handle SubprocessControllerError during shutdown
authorAleš Mrázek <ales.mrazek@nic.cz>
Wed, 29 Jan 2025 15:00:38 +0000 (16:00 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Wed, 5 Feb 2025 22:05:19 +0000 (23:05 +0100)
python/knot_resolver/manager/manager.py

index c26d9561651274b7db02976dbd2551c67db545f7..dcd14b537859d1a62007876328c6ad227955cb67 100644 (file)
@@ -351,8 +351,8 @@ class KresManager:  # pylint: disable=too-many-instance-attributes
 
     async def stop(self):
         if self._processes_watchdog_task is not None:
-            self._processes_watchdog_task.cancel()  # cancel it
             try:
+                self._processes_watchdog_task.cancel()  # cancel it
                 await self._processes_watchdog_task  # and let it really finish
             except asyncio.CancelledError:
                 pass
@@ -437,11 +437,17 @@ class KresManager:  # pylint: disable=too-many-instance-attributes
                     )
                     invoke_callback = True
 
+            except SubprocessControllerError as e:
+                # wait few seconds and see if 'processes_watchdog' task is cancelled (during shutdown)
+                # otherwise it is an error
+                await asyncio.sleep(3)
+                invoke_callback = True
+                logger.error(f"Processes watchdog failed with SubprocessControllerError: {e}")
             except asyncio.CancelledError:
                 raise
             except BaseException:
                 invoke_callback = True
-                logger.error("Knot Resolver processes watchdog failed with an unexpected exception.", exc_info=True)
+                logger.error("Processes watchdog failed with an unexpected exception.", exc_info=True)
 
             if invoke_callback:
                 try: