Skip to content

Conversation

@krwq
Copy link
Member

@krwq krwq commented Feb 12, 2021

Fixes #45010

This is a port of 5.0 change. There was a merge conflict with fdc8148 which I have resolved here.

Adding @eerhardt to validate this will not produce new ILLink warnings.

This is a fix related to dotnet/announcements#175

cc: @karelz @Anipik

@ghost
Copy link

ghost commented Feb 12, 2021

Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #45010

This is a port of 5.0 change. There was a merge conflict with fdc8148 which I have resolved her.

Adding @eerhardt to validate this will not produce new ILLink warnings

cc: @karelz @Anipik

Author: krwq
Assignees: -
Labels:

area-System.Security

Milestone: -

object? socketsHttpHandler = socketsHttpHandlerCtor.Invoke(null);
pooledConnectionIdleTimeoutProp.SetValue(socketsHttpHandler, TimeSpan.FromSeconds(PooledConnectionIdleTimeoutSeconds));
object? httpClient = Activator.CreateInstance(httpClientType, new object?[] { socketsHttpHandler });
allowAutoRedirectProp.SetValue(socketsHttpHandler, false);
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be worth including a todo comment citing that we should clean up this method if #45364 is ever implemented.


// Get the relevant types needed.
Type? socketsHttpHandlerType = Type.GetType("System.Net.Http.SocketsHttpHandler, System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: false);
Type? httpMessageHandlerType = Type.GetType("System.Net.Http.HttpMessageHandler, System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: false);
Copy link
Member

@stephentoub stephentoub Feb 12, 2021

Choose a reason for hiding this comment

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

This method is getting pretty complicated with all this reflection. As a follow-up, I wonder if it'd be worthwhile adding a single internal method to SocketsHttpHandler that does all this logic without reflection (and without duplication of code for getting a redirect Uri), and then just reflect to invoke that one member from here.

Copy link
Member

Choose a reason for hiding this comment

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

Apparently part of me still believes this is Core 1.0, because my initial thought was "but what about package shear?". Since we're both inbox I guess that's safe enough 😄

@bartonjs bartonjs merged commit f61c883 into dotnet:master Feb 12, 2021
// };
// var httpClient = new HttpClient(socketsHttpHandler);
object? socketsHttpHandler = Activator.CreateInstance(socketsHttpHandlerType);
// Note: using a ConstructorInfo instead of Activator.CreateInstance, so the ILLinker can see the usage through the lambda method.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this comment makes sense. This isn't being called inside the lambda method. It should be fine to continue calling Activator.CreateInstance here.

pooledConnectionIdleTimeoutProp.SetValue(socketsHttpHandler, TimeSpan.FromSeconds(PooledConnectionIdleTimeoutSeconds));
object? httpClient = Activator.CreateInstance(httpClientType, new object?[] { socketsHttpHandler });
allowAutoRedirectProp.SetValue(socketsHttpHandler, false);
object? httpClient = httpClientCtor.Invoke(new object?[] { socketsHttpHandler });
Copy link
Member

Choose a reason for hiding this comment

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

Why did this change from Activator.CreateInstance?

@ghost ghost locked as resolved and limited conversation to collaborators Mar 14, 2021
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.

Ubuntu18.04 net5.0 HttpClient SendAsync ignores timeout (via token), hangs for some time and eventually crash the app

4 participants