[release/6.0] Fix stress issues around multiple threads throwing the same exceptions...
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Mon, 23 Aug 2021 22:55:48 +0000 (15:55 -0700)
committerGitHub <noreply@github.com>
Mon, 23 Aug 2021 22:55:48 +0000 (15:55 -0700)
commitb7df9ff170c2276899456460cf494e2c3ba41940
tree36ab92d77eaa00481c60048451da0bebbc4c10fc
parent8ddb6335236416562dca5e00eddc812d1d0f3340
[release/6.0] Fix stress issues around multiple threads throwing the same exceptions (#57959)

* Fix stress issues around multiple threads throwing the same exceptions - The watson codebase manipulates the state of the following fields on Exception in a lock-free manner without locks if there are multiple threads throwing the same exception - _stackTrace - _stackTraceString - _remoteStackTraceString - _watsonBuckets - _ipForWatsonBuckets - The designed behavior is that these apis should "mostly" be correct, but as they are only used for fatal shutdown scenarios, exact correctness is not required for correct program execution - However, there are some race conditions that have been seen recently in testing 1. In some circumstances, the value will be explicitly read from multiple times, where the first read is to check for NULL, and then a second read is to read the actual value and use it in some way. In the presence of a race which sets the value to NULL, the runtime can crash. To fix this, the code is refactored in cases which could lead to crashes with a single read, and carrying around the read value to where it needs to go. 2. Since the C++ memory model generally allows a single read written in C++ to be converted into multiple reads if the compiler can prove that the read does not cross a lock/memory barrier, it is possible for the C++ compiler to inject multiple reads where the logic naturally only has 1. The fix for this is to utlilize the VolatileLoadWithoutBarrier api to specify that a read should happen once in cases where it might cause a problem.

Finally, the test45929 was tended to fail in GC stress as it would take a very long time to run under GC stress or on some hardware. Adjust it so that it shuts down after about 2.5 minutes.
- Do this instead of disabling running under gcstress as there is evidence that there may have been bugs seen during runs under gcstress.

Fixes #46803

* Rename as per suggestion

Co-authored-by: David Wrighton <davidwr@microsoft.com>
src/coreclr/debug/daccess/request.cpp
src/coreclr/vm/excep.cpp
src/coreclr/vm/exstatecommon.h
src/coreclr/vm/object.cpp
src/coreclr/vm/object.h
src/coreclr/vm/vars.hpp
src/tests/Regressions/coreclr/GitHub_45929/test45929.cs