-
Notifications
You must be signed in to change notification settings - Fork 417
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
Use ConcurrentDictionary in CachingScriptMetadataResolver #1627
Use ConcurrentDictionary in CachingScriptMetadataResolver #1627
Conversation
this type is duplicated for Cake too, could you fix it there too? https://github.com/OmniSharp/omnisharp-roslyn/blob/master/src/OmniSharp.Cake/CachingScriptMetadataResolver.cs |
} | ||
|
||
return result; | ||
return MissingReferenceCache.GetOrAdd(referenceIdentity.Name, _ => _defaultReferenceResolver.ResolveMissingAssembly(definition, referenceIdentity)); |
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.
I don't think it's the same thing as before. the old code would only cache non-nulls, whereas the new code would cache them.
In the second case it wouldn't cache empty collections too
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.
Yeah, that is true, But does it matter? If the _defaultReferenceResolver
returns null
, it would be null
for any subsequent requests too? So we save a call into the _defaultReferenceResolver
. Unless that could change between request. If it actually is important we can replace this with TryAdd
instead
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.
Or is it any other reason for this conditional caching? 😀
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.
LGTM thanks
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.
LGTM
This PR fixes a bug that was caused by multiple threads accessing the
DirectReferenceCache
and theMissingReferenceCache
inside theCachingScriptMetadataResolver
Occasionally, OmniSharp would fail to initialize for
csx
files with the following output from theOmniSharp
logThe fix is implemented by replacing the underlying
Dictionary
with aConcurrentDictionary