SourceMessage: fix race in access to actions collection (bgo#751582)
This foreach() loop had the potential problem of a typical race throwing a 'System.InvalidOperationException: Collection was modified; enumeration operation may not execute.' The normal thing to do in these cases is just to make a copy of the collection (via the .ToArray() method, for instance), at the beginning of the loop. However, this approach alone: a) would have presented a new race between the check for null and the call to the ToArray method. b) wouldn't have worked at compile time because IEnumerable<X> doesn't have this method (List<X> does). The proper way to fix (a) involves also avoiding to have a null value. How? Initializing the field always at construction time of the SourceMessage class. This has the good side-effect of being able to remove all null-checks around this field and its wrapper property. WRT (b) we could have created a new list at the beginning of the foreach loop, but it's more practical to just do the copy in the SourceMessage class, because, in the end, a read access should also involve lock()ing, otherwise writers to the collection could race with the readers of it.
Showing with 11 additions and 14 deletions