Fix race condition in DiagnosticSourceEventSource (dotnet/corefx#35269)
authorStephen Toub <stoub@microsoft.com>
Wed, 13 Feb 2019 19:10:51 +0000 (14:10 -0500)
committerGitHub <noreply@github.com>
Wed, 13 Feb 2019 19:10:51 +0000 (14:10 -0500)
commitce44605dfcd681e49b14921efaf5b1528ac6a80d
tree988eedddde6a1353f3a2909c7fd42c0ea9326dab
parent4ac9ce8f62877ae1e0f560d01a76e6bd5a2f4875
Fix race condition in DiagnosticSourceEventSource (dotnet/corefx#35269)

* Use RemoteInvoke in DiagnosticSourceEventListener tests

Running these concurrently with other tests in the same process can result in spurious failures.

* Fix race condition in DiagnosticSourceEventSource

If multiple threads all try to write different objects at the same time, PropertySpec.Fetch can manifest a race condition that results in potentially trying to cast one call's object to another call's type.  The fix is to allow for atomically storing the cached data, and using a local to ensure that a calling thread's view is consistent.

Commit migrated from https://github.com/dotnet/corefx/commit/7c50828052ba55e3474ff5dd29ee7fcf5bbfa03d
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs
src/libraries/System.Diagnostics.DiagnosticSource/tests/DiagnosticSourceEventSourceBridgeTests.cs
src/libraries/System.Diagnostics.DiagnosticSource/tests/System.Diagnostics.DiagnosticSource.Tests.csproj