From d4bf4721a7ea230883216fe6ff69f7b23a8b2fde Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Fri, 8 Oct 2021 03:24:41 -0500 Subject: [PATCH] Fix resume task. In some cases, the task is stopped and quickly resumed. In this cases there was race condition in which the scan id is present in the scan table but there is no target information. Although the quick resume can lead first into a stopped and scan followed by an interrupted scan, finally the scan can be resumed. --- CHANGELOG.md | 2 ++ ospd/scan.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 388d1839..24e9bee8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Deprecated ### Removed ### Fixed +- Fix resume scan. [#464](https://github.com/greenbone/ospd/pull/464) + [Unreleased]: https://github.com/greenbone/ospd/compare/v21.4.3...HEAD diff --git a/ospd/scan.py b/ospd/scan.py index dada3f92..8e479729 100644 --- a/ospd/scan.py +++ b/ospd/scan.py @@ -502,7 +502,17 @@ def get_end_time(self, scan_id: str) -> str: def get_host_list(self, scan_id: str) -> Dict: """ Get a scan's host list. """ - return self.scans_table[scan_id]['target'].get('hosts') + target = None + try: + target = self.scans_table[scan_id]['target'].get('hosts') + except KeyError: + LOGGER.warning( + '%s: Scan ID is in the scan table, but it was ' + 'not initialized.', + scan_id, + ) + + return target def get_host_count(self, scan_id: str) -> int: """ Get total host count in the target. """