Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Fix stop scan. #204

Merged
merged 3 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Update daemon start sequence. Run daemon.check before daemon.init now. [#197](https://github.com/greenbone/ospd/pull/197)
- Improve get_vts cmd response, sending the vts piece by piece.[#201](https://github.com/greenbone/ospd/pull/201)

### Fixed
- Fix stop scan. Wait for the scan process to be stopped before delete it from the process table. [#204](https://github.com/greenbone/ospd/pull/204)

## [2.0.1] (unreleased)

### Added
Expand Down
7 changes: 7 additions & 0 deletions ospd/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ def handle_xml(self, xml: Element) -> str:

self._daemon.stop_scan(scan_id)

# Don't send response until the scan is stopped.
try:
self._daemon.scan_processes[scan_id].join()
exitcode = self._daemon.scan_processes[scan_id].exitcode
except KeyError:
pass

return simple_response_str('stop_scan', 200, 'OK')


Expand Down
9 changes: 8 additions & 1 deletion ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,17 @@ def delete_scan(self, scan_id: str) -> int:
if self.get_scan_status(scan_id) == ScanStatus.RUNNING:
return 0

# Don't delete the scan until the process stops
exitcode = None
try:
del self.scan_processes[scan_id]
self.scan_processes[scan_id].join()
exitcode = self.scan_processes[scan_id].exitcode
except KeyError:
logger.debug('Scan process for %s not found', scan_id)

if exitcode or exitcode == 0:
del self.scan_processes[scan_id]

return self.scan_collection.delete_scan(scan_id)

def get_scan_results_xml(
Expand Down