While working on #2899 -- and trying to address the trimmer errors (^H "warnings"), I encountered RouteResolverDefault.cs and had concerns.
Firstly, thread safety:
|
public static IList<string> Excludes { get; } = new List<string>(); |
Generally, static members should be thread safe. AssemblyExtensions.Excludes is not: it's a List<string>, modifiable from AssemblyExtensions.SafeGetTypes(). If multiple threads try to use .SafeGetTypes() concurrently, .Excludes may be corrupted or the code may throw unexpectedly. Or RouteResolverDefault.LoadedTypes may throw if another thread modifies AssemblyExtensions.Excludes while it's executing.
Secondly, assembly loading semantics: RouteResolverDefault.LoadedTypes calls AppDomain.CurrentDomain.GetAssemblies() the first time it's invoked, saving the results. This seems somewhat "odd", in that nothing prevents assemblies from being loaded after the initial .LoadedTypes call, a'la:
- App launches
- App uses
RouteResolverDefault.LoadedTypes, set of types is cached.
- App uses
Assembly.Load*() to load a new assembly.
- Subsequent use of
RouteResolverDefault.LoadedTypes doesn't see types from (3).
Is this a problem?
While working on #2899 -- and trying to address the trimmer errors (^H "warnings"), I encountered
RouteResolverDefault.csand had concerns.Firstly, thread safety:
uno.extensions/src/Uno.Extensions.Navigation.UI/RouteResolverDefault.cs
Line 256 in 90f328b
Generally, static members should be thread safe.
AssemblyExtensions.Excludesis not: it's aList<string>, modifiable fromAssemblyExtensions.SafeGetTypes(). If multiple threads try to use.SafeGetTypes()concurrently,.Excludesmay be corrupted or the code may throw unexpectedly. OrRouteResolverDefault.LoadedTypesmay throw if another thread modifiesAssemblyExtensions.Excludeswhile it's executing.Secondly, assembly loading semantics:
RouteResolverDefault.LoadedTypescallsAppDomain.CurrentDomain.GetAssemblies()the first time it's invoked, saving the results. This seems somewhat "odd", in that nothing prevents assemblies from being loaded after the initial.LoadedTypescall, a'la:RouteResolverDefault.LoadedTypes, set of types is cached.Assembly.Load*()to load a new assembly.RouteResolverDefault.LoadedTypesdoesn't see types from (3).Is this a problem?