Fix thread-safety issues with enumerating ResourceManager. (#75054)
authormadelson <1269046+madelson@users.noreply.github.com>
Tue, 3 Jan 2023 17:32:42 +0000 (12:32 -0500)
committerGitHub <noreply@github.com>
Tue, 3 Jan 2023 17:32:42 +0000 (12:32 -0500)
commit15fcb990fe17348ab6ddde0939200b900169920b
treed1c509ba6f322fa6e726695fd2b49de14e68d292
parent6c2b93935c7a533eab8e661aac646c3815bd6593
Fix thread-safety issues with enumerating ResourceManager. (#75054)

* Fix thread-safety issues with enumerating ResourceManager.

Concurrently enumerating a ResourceManager while also calling GetString()
and similar methods was prone to both transient errors and deadlock.

The transient errors were caused by RuntimeResourceSet calling internal
methods on ResourceReader that did not properly lock. Now, all exposed
methods on the Reader are thread-safe.

The deadlock was called by inconsistent lock ordering between
ResourceReader.ResourceEnumerator and RuntimeResourceSet which both lock
on the RuntimeResourceSet's cache and on the ResourceReader itself. Now,
the enumerator does not need to take both locks at the same time.

Fix #74052
Fix #74868

* Remove trailing whitespace

* Address feedback from https://github.com/dotnet/runtime/pull/75054

* Add comment in response to https://github.com/dotnet/runtime/pull/75054#issuecomment-1317470280

* Implement feedback from https://github.com/dotnet/runtime/pull/75054
src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.cs
src/libraries/System.Private.CoreLib/src/System/Resources/RuntimeResourceSet.cs
src/libraries/System.Resources.Extensions/tests/BinaryResourceWriterUnitTest.cs
src/libraries/System.Resources.ResourceManager/tests/ResourceManagerTests.cs
src/libraries/System.Resources.ResourceManager/tests/Resources/AToZResx.Designer.cs [new file with mode: 0644]
src/libraries/System.Resources.ResourceManager/tests/Resources/AToZResx.resx [new file with mode: 0644]
src/libraries/System.Resources.ResourceManager/tests/System.Resources.ResourceManager.Tests.csproj