StackExchange.Redis icon indicating copy to clipboard operation
StackExchange.Redis copied to clipboard

Timeout exceptions when using Synchronous API in a multi-threaded application

Open darcon77 opened this issue 7 years ago • 4 comments

Program.txt

Attached please find a repro of the issues we're seeing with StackExchange.Redis v 2.x, however the issue is not present in 1.2.6;

Weird behavior when trying to access cache from multiple threads. If the above code is ran in debug mode, we see timeouts on all operations, no keys are added to cache. However if we run the same exact code without a debugger attached, the code seems to be working and adding keys to cache. As soon as i wrap the cache access methods in try/catch to see if the timeout exceptions are still present in non-debug mode, the code stops working and starts throwing more timeouts and nothing gets added to cache.

Could you please look into this?

P.S. Timeouts are present when accessing Redis on Azure, but disappear if we access Redis in our data center. Both, Azure Resource Group that hosts Azure Redis instance and our data center are in Eastern US

Thank you

darcon77 avatar May 13 '19 19:05 darcon77

I had this on my queue to look at today, but you seem to have got somewhere. I'm kinda surprised that it behaves particularly different between azure / not, and I'd still be open to taking a look if you get ongoing problems.

mgravell avatar May 14 '19 07:05 mgravell

@mgravell Do you have any explanation about why would it work without debugger attached, but fail when debugging?

darcon77 avatar May 14 '19 12:05 darcon77

I'm assuming you don't have anything like:

#if DEBUG
    options.SyncTimeout *= 100; // in case we break-point
#endif

but other than that... no, and I'm very curious! maybe something to do with sync context perhaps? what kind of app is it? web? desktop? (ideally down to ".NET 4.5.2 WPF desktop app on Windows 10", for example)

mgravell avatar May 14 '19 13:05 mgravell

The attached repro is a console app. I stripped out the exact code from the production application that was having the issues. The production application is a Windows service, .NET 4.6.2 running on Windows Server 2012.

P.S. I don't have the SyncTimeout code.

darcon77 avatar May 14 '19 14:05 darcon77