-
-
Notifications
You must be signed in to change notification settings - Fork 457
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
Single lookups into concurrent dictionary #2231
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
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.
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.
@kblok Do you recall if the lock in
AddTargetInterceptor
intended to lock both the usage of_targetInterceptors
and adding an element tointerceptors
?A colleague of mine pointed out that I might have introduced a race-condition here
If two threads get the same
interceptors
out of_targetInterceptors
and concurrently calls the thread-unsafeList<T>.Add
.On the other hand the other usages of
interceptors
are also not lockedRemoveTargetInterceptor
removes an item from the listOnAttachedToTarget
enumerates the listThere 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.
Is that a theory or a suspicion? We are talking about multiple threads, but I don't see how those events coming from the browser could be racy.
But yeah. The goal of the lock was to make those two actions thread-safe.
We could restore the lock. We could also turn the list into a
ConcurrentSet
.Again, I don't see how we can get a race in
RemoveTargetInterceptor
I can see the need for a lock there.
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.
Before this PR the non-thread safe
interceptors.Add(interceptor);
was inside a lock and now it isn't.I didn't notice that slight change of semantics when I created the PR, that's why I'm bringing it to your attention.
We haven't experienced that any problems that I suspect stem from this PR, so for now it's a theoretical race-condition.
I assume that's what you meant by "theory or a suspicion"?
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.
@jnyrup yes. I was curious whether you did got a race condition or you found it could be a problem.
I think we could make it a
ConcurrentSet
just in case.