diff --git a/CHANGELOG.md b/CHANGELOG.md index e59f87d0..183a0a16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Set loglevel to debug for some message. [#159](https://github.com/greenbone/ospd/pull/159) +- Improve error handling when stop a scan. [#163](https://github.com/greenbone/ospd/pull/163) ### Fixed - Fix set permission in unix socket. [#157](https://github.com/greenbone/ospd/pull/157) diff --git a/ospd/ospd.py b/ospd/ospd.py index 8f203bb6..7ad6ae82 100644 --- a/ospd/ospd.py +++ b/ospd/ospd.py @@ -659,7 +659,12 @@ def stop_scan(self, scan_id): except AttributeError: logger.debug('%s: The scanner task stopped unexpectedly.', scan_id) - os.killpg(os.getpgid(scan_process.ident), 15) + try: + os.killpg(os.getpgid(scan_process.ident), 15) + except ProcessLookupError as e: + logger.info('%s: Scan already stopped %s.', + scan_id, scan_process.ident) + if scan_process.ident != os.getpid(): scan_process.join() logger.info('%s: Scan stopped.', scan_id)