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

Disable default HttpClient/HttpWebRequest timeouts #18050

Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion sdk/core/Azure.Core/src/Pipeline/HttpClientTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ private static HttpClient CreateDefaultClient()
ServicePointHelpers.SetLimits(httpClientHandler);
#endif

return new HttpClient(httpClientHandler);
return new HttpClient(httpClientHandler)
{
// Timeouts are handled by the pipeline
Timeout = Timeout.InfiniteTimeSpan
};
}

private static HttpRequestMessage BuildRequestMessage(HttpMessage message)
Expand Down
6 changes: 6 additions & 0 deletions sdk/core/Azure.Core/src/Pipeline/HttpWebRequestTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;

namespace Azure.Core.Pipeline
Expand Down Expand Up @@ -110,6 +111,11 @@ private async ValueTask ProcessInternal(HttpMessage message, bool async)
private HttpWebRequest CreateRequest(Request messageRequest)
{
var request = WebRequest.CreateHttp(messageRequest.Uri.ToUri());

// Timeouts are handled by the pipeline
request.Timeout = Timeout.Infinite;
request.ReadWriteTimeout = Timeout.Infinite;
Copy link
Contributor

Choose a reason for hiding this comment

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

https://docs.microsoft.com/en-us/dotnet/api/system.net.httpwebrequest.readwritetimeout?view=net-5.0#remarks this talks about timeouts on Stream.Write as well. I recall we apply NetworkTimeout on Stream.Read. How is Stream.Write secured by NetworkTimeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now the only Write we do is during content sending. The content is written during the Transport.SendAsync call and is guarded by this timeout:

https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/src/Pipeline/Internal/ResponseBodyPolicy.cs#L43-L60

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the thorough review.


// Don't disable the default proxy when there is no environment proxy configured
if (_environmentProxy != null)
{
Expand Down