Particular / NServiceBus.Transport.AzureServiceBus

Azure Service Bus transport
Other
22 stars 19 forks source link

Fix thread-safe comparison used to optimize circuit breaker's Success method #1056

Closed DavidBoike closed 2 months ago

DavidBoike commented 2 months ago

The circuit breaker's Success() method must be as close to a no-op as possible on the happy path, but when disarming in a multi-threaded environment still needs to run the disarm logic only once.

Previously, while querying values was done in a thread-safe way, a thread on the Failure method could pause while a Success() call ran to entirety, setting the failure count to 0, and ensuring that further calls to Success() would see a failure count of 0 and take no action, even though the arming action had been executed most recently.

This resulted in a scenario where no number of Success calls could undo the armedAction, unless another Failure call went first.

danielmarbach commented 2 months ago

Here is a hopefully simplified version https://github.com/Particular/NServiceBus.Transport.AzureServiceBus/pull/1057

DavidBoike commented 2 months ago

Closing in favor of https://github.com/Particular/NServiceBus.Transport.AzureServiceBus/pull/1057