Skip to content

Commit 4536be6

Browse files
jr01richardszalay
authored andcommitted
Fix outstanding requests exception message
Fixes a concurrency issue where between lines `outstandingRequests > 0` and `throw new InvalidOperationException` another thread would increment/decrement `outstandingRequests`. See https://stackoverflow.com/a/24893231 Fixes `oustanding` to `outstanding` in the exception message.
1 parent 4cbeea8 commit 4536be6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

RichardSzalay.MockHttp.Shared/MockHttpMessageHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,9 @@ protected override void Dispose(bool disposing)
267267
/// </summary>
268268
public void VerifyNoOutstandingRequest()
269269
{
270-
if (outstandingRequests > 0)
271-
throw new InvalidOperationException("There are " + outstandingRequests + " oustanding requests. Call Flush() to complete them");
270+
var requests = Interlocked.CompareExchange(ref outstandingRequests, 0, 0);
271+
if (requests > 0)
272+
throw new InvalidOperationException("There are " + requests + " outstanding requests. Call Flush() to complete them");
272273
}
273274

274275
/// <summary>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy