Skip to content

Commit

Permalink
Revert "Add response read timeouts (Azure#10128)" (Azure#10168)
Browse files Browse the repository at this point in the history
This reverts commit c4c10ac.
  • Loading branch information
pakrym authored Feb 26, 2020
1 parent 137ab97 commit 857f8db
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 594 deletions.
2 changes: 0 additions & 2 deletions sdk/core/Azure.Core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Release History

## 1.1.0-preview.1 (Unreleased)

### Fixes and improvements
- Add OPTIONS and TRACE HTTP request methods.
- Add `NetworkTimeout` property to `RetryOptions` and apply it to network operations like sending request or reading from the response stream.

## 1.0.2 (2020-01-10)

Expand Down
1 change: 0 additions & 1 deletion sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ internal RetryOptions() { }
public System.TimeSpan MaxDelay { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public int MaxRetries { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public Azure.Core.RetryMode Mode { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
public System.TimeSpan NetworkTimeout { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
}
public abstract partial class TokenCredential
{
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/Azure.Core/src/Pipeline/HttpPipelineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static HttpPipeline Build(ClientOptions options, HttpPipelinePolicy[] per
diagnostics.LoggedHeaderNames.ToArray(), diagnostics.LoggedQueryParameters.ToArray()));
}

policies.Add(new ResponseBodyPolicy(options.Retry.NetworkTimeout));
policies.Add(BufferResponsePolicy.Shared);

policies.Add(new RequestActivityPolicy(isDistributedTracingEnabled, ClientDiagnostics.GetResourceProviderNamespace(options.GetType().Assembly)));

Expand Down
58 changes: 58 additions & 0 deletions sdk/core/Azure.Core/src/Pipeline/Internal/BufferResponsePolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.IO;
using System.Threading.Tasks;

namespace Azure.Core.Pipeline
{
internal class BufferResponsePolicy : HttpPipelinePolicy
{
protected BufferResponsePolicy()
{
}

public static HttpPipelinePolicy Shared { get; set; } = new BufferResponsePolicy();

public override async ValueTask ProcessAsync(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline)
{
await ProcessNextAsync(message, pipeline).ConfigureAwait(false);

if (message.BufferResponse)
{
await BufferResponse(message, true).ConfigureAwait(false);
}
}

public override void Process(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline)
{
ProcessNext(message, pipeline);

if (message.BufferResponse)
{
BufferResponse(message, false).EnsureCompleted();
}
}

private static async ValueTask BufferResponse(HttpMessage message, bool async)
{
if (message.Response.ContentStream != null && !message.Response.ContentStream.CanSeek)
{
Stream responseContentStream = message.Response.ContentStream;
var bufferedStream = new MemoryStream();
if (async)
{
await responseContentStream.CopyToAsync(bufferedStream).ConfigureAwait(false);
}
else
{
responseContentStream.CopyTo(bufferedStream);
}
responseContentStream.Dispose();
bufferedStream.Position = 0;
message.Response.ContentStream = bufferedStream;
}
}
}
}
128 changes: 0 additions & 128 deletions sdk/core/Azure.Core/src/Pipeline/Internal/ReadTimeoutStream.cs

This file was deleted.

129 changes: 0 additions & 129 deletions sdk/core/Azure.Core/src/Pipeline/Internal/ResponseBodyPolicy.cs

This file was deleted.

5 changes: 0 additions & 5 deletions sdk/core/Azure.Core/src/RetryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,5 @@ internal RetryOptions()
/// The approach to use for calculating retry delays.
/// </summary>
public RetryMode Mode { get; set; } = RetryMode.Exponential;

/// <summary>
/// The timeout applied to an individual network operations.
/// </summary>
public TimeSpan NetworkTimeout { get; set; } = TimeSpan.FromSeconds(100);
}
}
11 changes: 4 additions & 7 deletions sdk/core/Azure.Core/src/Shared/RetriableStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,14 @@ public override async Task<int> ReadAsync(byte[] buffer, int offset, int count,
}
catch (Exception e)
{
await RetryAsync(e, true, cancellationToken).ConfigureAwait(false);
await RetryAsync(e, true).ConfigureAwait(false);
}
}
}

private async Task RetryAsync(Exception exception, bool async, CancellationToken cancellationToken)
private async Task RetryAsync(Exception exception, bool async)
{
bool isNonCustomerCancelledException = exception is OperationCanceledException &&
!cancellationToken.IsCancellationRequested;

if (!_responseClassifier.IsRetriableException(exception) && !isNonCustomerCancelledException)
if (!_responseClassifier.IsRetriableException(exception))
{
ExceptionDispatchInfo.Capture(exception).Throw();
}
Expand Down Expand Up @@ -135,7 +132,7 @@ public override int Read(byte[] buffer, int offset, int count)
}
catch (Exception e)
{
RetryAsync(e, false, default).EnsureCompleted();
RetryAsync(e, false).EnsureCompleted();
}
}
}
Expand Down
Loading

0 comments on commit 857f8db

Please sign in to comment.