
The Build method uses a non-atomic check-and-set pattern on a ConcurrentDictionary (TryGetValue followed by Add). In a multi-threaded environment, this can lead to an ArgumentException if multiple threads attempt to add the same key simultaneously, causing the game session to terminate. Additionally, the cache uses args.GetType() as the key while resolving the builder based on typeof(TArgs). If the method is called with the same argument type but different generic type parameters, it may retrieve a cached builder that cannot be cast to the expected interface, leading to an InvalidCastException and session termination.
Originally posted by @gemini-code-assist[bot] in #83 (comment)
The
Buildmethod uses a non-atomic check-and-set pattern on aConcurrentDictionary(TryGetValuefollowed byAdd). In a multi-threaded environment, this can lead to anArgumentExceptionif multiple threads attempt to add the same key simultaneously, causing the game session to terminate. Additionally, the cache usesargs.GetType()as the key while resolving the builder based ontypeof(TArgs). If the method is called with the same argument type but different generic type parameters, it may retrieve a cached builder that cannot be cast to the expected interface, leading to anInvalidCastExceptionand session termination.Originally posted by @gemini-code-assist[bot] in #83 (comment)