Closed
Description
Even though JsonDocument
is nominally immutable (modulo disposability), the internal GetString
implementation employs a caching scheme that is not thread safe:
Since the cached field is a struct that cannot be written to or read from atomically. It might be that we could fix this in the code using a regular System.Tuple
, thus ensuring atomic access to cached entries. Obviously this has the downside of incurring one additional allocation, but at least we can guarantee immutability (modulo disposability of course).
Related to #17975
Originally posted by @eiriktsarpalis in dotnet/docs#20563 (comment)