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

feat(iot-service, shared): Add support for configuring http connection lease timeouts #1874

Merged
merged 3 commits into from
Apr 9, 2021

Conversation

timtay-microsoft
Copy link
Member

@timtay-microsoft timtay-microsoft commented Apr 2, 2021

(This PR works now) The gist of it is that the servicepointmanager timeout properties work fine for .NET framework applications, but .NET core requires you to construct a SocketsHttpHandler as the basehandler in order to solve this issue. This very closely mimics how Azure.Core solves this same issue.

@timtay-microsoft timtay-microsoft changed the title Attempt to solve DNS refresh issue like track 2 library did Attempt to solve DNS refresh issue like Azure.Core does Apr 2, 2021
@timtay-microsoft timtay-microsoft marked this pull request as ready for review April 7, 2021 23:29
@timtay-microsoft
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@timtay-microsoft timtay-microsoft changed the title Attempt to solve DNS refresh issue like Azure.Core does feat(iot-service, shared): Add support for configuring http connection lease timeouts Apr 8, 2021
Copy link
Member

@abhipsaMisra abhipsaMisra left a comment

Choose a reason for hiding this comment

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

A comment about DigitalTwinClient constructors, others are minor.

@Azure Azure deleted a comment from azure-pipelines bot Apr 8, 2021
@Azure Azure deleted a comment from azure-pipelines bot Apr 8, 2021
…timeout in Http service clients

Also fixes #1865 by making the default connection lease timeout no longer infinite
HttpMessageHandler httpMessageHandler = new HttpClientHandler();
#endif
// Currently, the connection lease timeout isn't configurable in this client. This may be worth adding later though
ServicePointHelpers.SetLimits(httpMessageHandler, uri, ServicePointHelpers.DefaultConnectionLeaseTimeout);
Copy link
Member Author

Choose a reason for hiding this comment

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

Since there isn't a great way to add the option to configure this connection lease timeout, I'll just leave it as the default for now. We can always add a constructor later that takes this as a configurable option if a customer asks for it

servicePoint.ConnectionLeaseTimeout = connectionLeaseTimeoutMilliseconds;
break;
#if NETCOREAPP
case SocketsHttpHandler socketsHttpHandler:
Copy link
Member

Choose a reason for hiding this comment

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

netcoreapp1.0-2.0 won't send the messageHandler as a socket http handler, so this switch block won't be executed, but do you think excluding those versions in the if-def is in any way useful?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll make this if-def match the if-def I have where we decide to make this handler a SocketsHttpHandler vs HttpClientHandler to make this moot

@Azure Azure deleted a comment from azure-pipelines bot Apr 9, 2021
@timtay-microsoft timtay-microsoft merged commit 8df9dd7 into master Apr 9, 2021
@timtay-microsoft timtay-microsoft deleted the timtay/takeTwo branch April 9, 2021 21:03
DelegatingHandler handler = handlers[i];
// Non-delegating handlers are ignored since we always
// have RetryDelegatingHandler as the outer-most handler
while (handler.InnerHandler is DelegatingHandler)
Copy link
Contributor

Choose a reason for hiding this comment

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

curious if you could have done: while (handler.InnerHandler is DelegatingHandler delegatingHandler)

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly. I didn't want to alter this code more than I needed to though since it was copied from track 2 and is designed to mimic the behavior that we already had. I just wanted this method to accept the more generic HttpMessageHandler rather than a HttpClientHandler

// have RetryDelegatingHandler as the outer-most handler
while (handler.InnerHandler is DelegatingHandler)
{
handler = handler.InnerHandler as DelegatingHandler;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should only use as if you are unsure it is that type, because it will otherwise return null. When you are sure (and you are because of the check in the while loop), you should just cast (assertive).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. This code was copied from the track 2 folks, so I missed this

@@ -27,5 +27,19 @@ public HttpTransportSettings()
/// especially when MQTT and AMQP ports are disallowed to the internet.
/// </remarks>
public IWebProxy Proxy { get; set; }

/// <summary>
/// How long, in milliseconds, a given cached TCP connection created by this client's HTTP layer will live before being closed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nicely written docs :)

timstewartm pushed a commit to timstewartm/azure-iot-sdk-csharp that referenced this pull request May 30, 2024
…n lease timeouts (Azure#1874)

Also fixes Azure#1865 by making the default connection lease timeout no longer infinite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants