Open chrisoverzero opened 1 week ago
Firstly: we should probably move this to dotnet/extensions (where HybridCache resides now); not sure I have access to do that, but...
I'll look at the repro tomorrow; one part of me is thinking "but what when the ambient state differs between callers", but: we already allow that foot-shotgun in the regular delegate scenario, so it s perhaps moot to worry about that specifically here. When I see the repro I might have more context; I'm guessing it is the fact that we don't have the ambient http-request precisely because we fork the onward call and await it (as part of the stampede protection).
Random thought: one option I was discussing the other day was a new flag to disable the stampede protection. If we did that: we would not be context switching - the primary execution flow could involve the callback. Would losing stampede protection be an acceptable trade for ambient http-request access?
we should probably move this to dotnet/extensions
Oops, sorry, I didn't realize the library had moved.
we already allow that foot-shotgun in the regular delegate scenario
I'm afraid I'll be no help there – I don't know what that means. 😅 Is GetOrCreateAsync
not the expected entry point?
Would losing stampede protection be an acceptable trade for ambient http-request access?
For me, for the project in which I discovered this: yes.
The GetOrCreateAsync is fine and expected.
Is there an existing issue for this?
Describe the bug
HttpClient
to the DI container viaAddHttpClient
from "Microsoft.Extensions.Http". ("inner service")HybridCache
to the DI container. ("outer service")factory
argument ofGetOrCreateAsync
onHybridCache
.HttpClient
. (Say, "etag".)When the
HttpClient
-depending method is called from theHybridCache
, anInvalidOperationException
is thrown, saying that the headers collection has not been initialized. When the call is moved out ofGetOrCreateAsync
, it succeeds.Expected Behavior
HybridCache
.Steps To Reproduce
curl --include --url 'http://localhost:8080/widgets/1' --header "etag: W/'1'"
._innerClient.GetWidgetAsync
inCachingWidgetClient
.Exceptions (if any)
.NET Version
9.0.100-rc.1.24452.12, 9.0.100-rc.2.24474.11
Anything else?
No response