Skip to content

Commit

Permalink
Merge pull request greenbone#204 from jjnicola/stop-race
Browse files Browse the repository at this point in the history
Fix stop scan.
  • Loading branch information
jjnicola authored Feb 12, 2020
2 parents 67b0747 + 354baa8 commit 8945f94
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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

0 comments on commit 8945f94

Please sign in to comment.