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

Don't iterate directly over the scans table, as it can change during the iteration. #304

Merged
merged 1 commit into from
Jul 24, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix get_scanner_details(). [#210](https://github.com/greenbone/ospd/pull/210)
- Fix thread lib leak using daemon mode for python 3.7. [#272](https://github.com/greenbone/ospd/pull/272)
- Fix scan progress in which all hosts are dead or excluded. [#295](https://github.com/greenbone/ospd/pull/295)
- Fix start of parallel queued task. [#304](https://github.com/greenbone/ospd/pull/304)

### Removed
- Remove support for resume task. [#266](https://github.com/greenbone/ospd/pull/266)
Expand Down
5 changes: 4 additions & 1 deletion ospd/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ def results_iterator(
def ids_iterator(self) -> Iterator[str]:
""" Returns an iterator over the collection's scan IDS. """

return iter(self.scans_table.keys())
# Do not iterate over the scans_table because it can change
# during iteration, since it is accessed by multiple processes.
scan_id_list = list(self.scans_table)
return iter(scan_id_list)

def clean_up_pickled_scan_info(self) -> None:
""" Remove files of pickled scan info """
Expand Down
8 changes: 8 additions & 0 deletions tests/test_scan_and_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,3 +1309,11 @@ def test_count_queued_scans(self):
self.assertEqual(self.daemon.get_count_queued_scans(), 1)
self.daemon.start_queued_scans()
self.assertEqual(self.daemon.get_count_queued_scans(), 0)

def test_ids_iterator_dict_modified(self):
self.daemon.scan_collection.scans_table = {'a': 1, 'b': 2}

for _ in self.daemon.scan_collection.ids_iterator():
self.daemon.scan_collection.scans_table['c'] = 3

self.assertEqual(len(self.daemon.scan_collection.scans_table), 3)