NimbusAPI / Nimbus

Nimbus is a .NET client library to provide an easy abstraction over common messaging frameworks.
http://nimbusapi.com/
MIT License
112 stars 84 forks source link

Incorrect expiry of RequestResponseCorrelationWrapper #271

Closed teyc closed 4 years ago

teyc commented 7 years ago

I've observed error logs reporting that _semaphore has already been disposed at this line https://github.com/NimbusAPI/Nimbus/blob/master/src/Nimbus/Infrastructure/RequestResponse/BusRequestSender.cs#L77

Here's what might be happening -

Under load, if services are slow to respond to Nimbus requests, the ResponseCorrelationWrapper could have expired and disposed before l WaitForResponse gets called https://github.com/NimbusAPI/Nimbus/blob/master/src/Nimbus/Infrastructure/RequestResponse/BusRequestSender.cs#L103

The expiry time is calculated here https://github.com/NimbusAPI/Nimbus/blob/master/src/Nimbus/Infrastructure/RequestResponse/BusRequestSender.cs#L77 and depending on how busy the threadpool is, it can be a while before it gets to line 103.

Options for fixing this are

  1. checking the RequestResponseCorrelationWrapper instance and see whether it has been disposed or not before proceeding,
  2. calculating the ExpiryTime dynamically based on whether the request has been sent