-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microsoft.Extensions.Caching.StackExchangeRedis 9.0.3 - when using HybridCache RedisCacheImpl.IsHybridCacheDefined causes infinite recursion #60894
Comments
I have also experienced exactly the same issue with HybridCache and Redis |
FYI this also happens with the 9.2.0 preview of |
@EsgAtWorkleap Yes, because the problem is with |
Investigating as a priority; some weird DI interplay - will get to the bottom of it. I have checked, and I'm certain that the only change in 9.0.3 is this metadata discovery, so it should be entirely safe and reasonable to use 9.0.2 as a workaround for now, and: any fix is going to be to Microsoft.Extensions.Caching.StackExchangeRedis: - <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.3" />
+ <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.2" /> |
Huge apologies. Fix PR is #60915 (main) and #60916 (backport to 9.x). I'm going to see if I can get 9.0.3 unlisted.
Yes: just avoid 9.0.3 of Microsoft.Extensions.Caching.StackExchangeRedis - 9.0.2 is fine, or if you're reading in the future: something >= 9.0.4 Not trying to make excuses here - this was just a stupid and (with hindsight) avoidable error. Both pieces unit tested absolutely fine in isolation, *sigh*. The following is purely for education to stop anyone else making the same mistake, and isn't me trying to dodge accountability:
The fix is simple: at least one of the two should defer asking questions until after it has been constructed The moral / learning point: if you're going to fake your DI: don't make it too fake Side note: I wonder if the DI could do a better job of detecting stack dives. In an ideal world, the DI would also have a "do you have a service registration for X?" API that doesn't actually force X to be manifested! |
Microsoft.Extensions.Caching.StackExchangeRedis 9.0.3 has been delisted - the underlying fixes will be applied presumably for 9.0.4, but until then: |
Thanks so much for jumping on this so quickly @mgravell! |
Note .NET 10 preview 1 and 2 presumably also have this issue; we're discussing whether it is preferable to leave that alone versus delist that - 9.0.2 should work perfectly fine with .NET 10, but it may be confusing that it doesn't exist, and this issue only occurs with the interaction between both libraries. |
) fix #60894 Co-authored-by: Marc Gravell <[email protected]>
9.0.4 of this library shipped without this fix so 9.0.4 results in a deadlock when using HybridCache |
Is there an existing issue for this?
Describe the bug
Hello guys.
Today I updated all my NuGets and my .NET 9 Back-End hanged.
I'm using the following NuGets to do the caching stuff in my project:
Microsoft.Extensions.Caching.Hybrid 9.3.0
Microsoft.Extensions.Caching.StackExchangeRedis 9.0.3
After investigating the issue and inspecting this GitHub repository I've find out what's happening:
I registered
HybridCache
like this:and then added some
RedisCache
like this:The problem here is with
IsHybridCacheDefined
method:When it resolves
HybridCache
which then resolvesIDistributedCache
.According to
StackExchangeRedisCacheServiceCollectionExtensions
,RedisCacheImpl
is registered as:So when resolving
IDistributedCache
and instantiatingRedisCacheImpl
, it'sctor
callsIsHybridCacheDefined
method, which resolvesHybridCache
, which resolvesIDistributedCache
resulting into an infinite resolution loop.With
Microsoft.Extensions.Caching.StackExchangeRedis 9.0.2
-RedisCacheImpl
has noIsHybridCacheDefined
method, so everything works fine.Expected Behavior
No response
Steps To Reproduce
services.AddHybridCache
, thenservices.AddStackExchangeRedisCache
HybridCache
anywhere (i.e. Controller/Minimal API)Exceptions (if any)
No response
.NET Version
9.0.201
Anything else?
No response
The text was updated successfully, but these errors were encountered: