Closed PavlovicDzFilip closed 2 months ago
This is a simple fix to ensure the methods of ConcurrentCommandCounter
class are thread safe.
However, there is a smell about the counter itself. There should never be any concurrency when handling the requests.
Summary & Motivation
In rare conditions, the code allows the unit of work and/or the events to not be published at the end of the request.
Multiple threads can decrement the concurrent counter at the same time using Interlocked to ensure atomicity of the operation. However, when reading the data, Interlocked was not used, leading to potential race conditions.
Note: I am aware there is no concurrency involved in here. But the counter itself has partial support for thread safety, and this is addressed in the PR.
Checklist