Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class HttpMessageInvoker : IDisposable
{
private volatile bool _disposed;
private readonly bool _disposeHandler;
// Do not make the _handler field public.
// Exposing it might interfere with HttpClientFactory handler recycling behavior.
Copy link
Member

@stephentoub stephentoub Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment.
a) We would never make _handler public for .NET API design reasons.
b) It's unclear how exposing the additional information (e.g. as a get-only property) would interfere with recycling behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user has access to the instance, they could then keep it alive longer than the client (by storing it somewhere) and that would break the recycling logic in HCF. This was one of the recommendations coming out of a discussion about HCF Threat Model.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about GC lifetime? The HttpMessageInvoker itself stores a reference to it. If the user is holding on to the HttpMessageInvoker, they're holding on to the handler indirectly. Moreover, to construct HttpMessageInvoker requires passing the handler into the ctor, so whoever constructed the HttpMessageInvoker could still be holding a direct reference to the instance.

private readonly HttpMessageHandler _handler;

public HttpMessageInvoker(HttpMessageHandler handler)
Expand Down
Loading