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

Commit

Permalink
Don't iterate directly over the scans table, as it can change during …
Browse files Browse the repository at this point in the history
…the iteration.

The scans table is accessed by different processes and the iterated dictionary can
change it size.
  • Loading branch information
jjnicola committed Jul 24, 2020
1 parent 44a2493 commit e4eade4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
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 e 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)

0 comments on commit e4eade4

Please sign in to comment.