-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve 'collection modified' exception when logging results #2549
Conversation
SingleWriter = true, | ||
SingleReader = true, | ||
}; | ||
readyToHashChannel = Channel.CreateBounded<int>(channelOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Gets or sets a boolean value that indicates whether the Results | ||
/// object associated with this logger is fixed and ready to replay. | ||
/// </summary> | ||
public bool CacheFinalized { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SingleWriter = true, | ||
SingleReader = true, | ||
}; | ||
readyToHashChannel = Channel.CreateBounded<int>(channelOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a line break here and six lines down to improve readability?
findFiles.Wait(); | ||
hashFiles.Wait(); | ||
// 4: A single-threaded consumer watches for completed scans | ||
// and logs results, if any. This operation is singlle-threaded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change introduces thread-safe utilization of a single CachingLogger instance in cases when multiple files with the same file hash are analyzed.
In these circumstances, the scan should not occur again, rather, the cached results (if any) should be updated (to reflect the current file path of the duplicated file) and 'replayed' into the log.
This is tricky because the scan pipeline design is intended for every context object (per scan target) to be accessed only on a single thread.
To make this work, we introduce a slim semaphore in the caching logger, which allows access to only a single thread at a time. This semaphore's
Wait
method is invoked on receiving the notice that a new scan target is being analyzed.We also have a new ReleaseLock method, which is called after scan completes. This method releases the semaphore and also puts the caching logger into a 'committed' state, meaning that the first copy, by file hash, of a set of duplicated targets has been analyzed and we now have a fixed set of results that can be 'replayed' into the log.
@suvamM