Fix race condition in FileAccessRepository#51
Merged
Conversation
Collaborator
|
Is this sufficient for the .NET memory model? |
johnterickson
approved these changes
Jan 29, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix race condition in FileAccessRepository
Today when we allow file accesses after project completion, we avoid disposing the log file stream and relevant to this bug we also avoid nulling out the
fileTableanddeletedDirectories. outside the lock we enumerate these collections to return aFileAccessesto the plugin. If a file access comes in while we're enumerating, we can get an exception like this:On solution would be to put
ProcessFileAccessesinside the lock. However, upon thinking about it, I realized that we don't need to avoid nulling out those collections and we should just do it regardless. There are already null checks on these collections when they're added to, so there is safety from that aspect. For the data loss, we anyway only use those collections when the project is reported as complete, so it does not hurt anything to just avoid adding to the collections (by nulling them out) after the project finishes.I am leaving the avoidance of the log file stream disposal though so we can still get the logging for these files. Also, I added a log line for the project finishing to have a clear delineation between accesses which end up being considered vs those which are missed in the logs.