Skip to content
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

[Group 4] Enable nullable annotations for Microsoft.Extensions.Http #66891

Merged
merged 4 commits into from
Mar 29, 2022

Conversation

maxkoshevoi
Copy link
Contributor

Related to #43605

Questions:

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Mar 19, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added area-Extensions-HttpClientFactory new-api-needs-documentation and removed community-contribution Indicates that the PR has been added by a community member labels Mar 19, 2022
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Mar 19, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Related to #43605

Questions:

Author: maxkoshevoi
Assignees: -
Labels:

new-api-needs-documentation, area-Extensions-HttpClientFactory

Milestone: -

@CarnaViire
Copy link
Member

Questions:
InnerHandler can be null

InnerHandler cannot be null if DefaultHttpClientFactory is used.

Code links below.

ExpiredHandlerTrackingEntry.InnerHandler is assigned only in .ctor from ActiveHandlerTrackingEntry.Handler.InnerHandler.

ActiveHandlerTrackingEntry.Handler is assigned only in .ctor, and ActiveHandlerTrackingEntry is created only in one place where LifetimeTrackingHttpMessageHandler is also explicitly created.

LifetimeTrackingHttpMessageHandler.InnerHandler is always assigned in .ctor (it cannot be unassigned).

LifetimeTrackingHttpMessageHandler is derived from DelegatingHandler. DelegatingHandler.InnerHandler disallows null on assignment. So even if null is somehow passed to LifetimeTrackingHttpMessageHandler's .ctor -- it might be achievable by substituting HttpMessageHandlerBuilder in DI and making Build() return null -- DelegatingHandler's .ctor will throw.

public ExpiredHandlerTrackingEntry(ActiveHandlerTrackingEntry other)
{
Name = other.Name;
Scope = other.Scope;
_livenessTracker = new WeakReference(other.Handler);
InnerHandler = other.Handler.InnerHandler;

var handler = new LifetimeTrackingHttpMessageHandler(builder.Build());
// Note that we can't start the timer here. That would introduce a very very subtle race condition
// with very short expiry times. We need to wait until we've actually handed out the handler once
// to start the timer.
//
// Otherwise it would be possible that we start the timer here, immediately expire it (very short
// timer) and then dispose it without ever creating a client. That would be bad. It's unlikely
// this would happen, but we want to be sure.
return new ActiveHandlerTrackingEntry(name, handler, scope, options.HandlerLifetime);

public LifetimeTrackingHttpMessageHandler(HttpMessageHandler innerHandler)
: base(innerHandler)

[DisallowNull]
public HttpMessageHandler? InnerHandler
{
get
{
return _innerHandler;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}

@CarnaViire CarnaViire self-requested a review March 21, 2022 19:01
Copy link
Member

@CarnaViire CarnaViire left a comment

Choose a reason for hiding this comment

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

Thanks a lot! LGTM, with one nit.

Copy link
Member

@CarnaViire CarnaViire left a comment

Choose a reason for hiding this comment

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

Thanks!

@CarnaViire CarnaViire merged commit 382490b into dotnet:main Mar 29, 2022
@maxkoshevoi maxkoshevoi deleted the mk/43605-http branch March 29, 2022 14:39
@karelz karelz added this to the 7.0.0 milestone Apr 8, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants