Skip to content

Commit 0cdd118

Browse files
authored
Avoid exception when setting the network stream timeout (Azure#17791)
Fixes: Azure#17781 Also avoids an annoying exception that shows up in VS Debug Output windows constantly. Before (using `dotnet run -c Release -f netcoreapp2.1 -- Download -s 10000`): ``` === Test === Current Total 3206 3206 3354 6560 3291 9851 3323 13174 3371 16545 3434 19979 3563 23542 3677 27219 3323 30542 3265 33807 === Results === Completed 33807 operations in a weighted-average of 10.01s (3,378.15 ops/s, 0.000 s/op) ``` After: ``` === Test === Current Total 4182 4182 4169 8351 4153 12504 4268 16772 4246 21018 4158 25176 4195 29371 4199 33570 4270 37840 3851 41691 === Results === Completed 41691 operations in a weighted-average of 10.02s (4,160.27 ops/s, 0.000 s/op) ``` **Azure.Core 1.0.2** ``` === Test === Current Total 4215 4215 4265 8480 4105 12585 4679 17264 4376 21640 4385 26025 4132 30157 4518 34675 4575 39250 3728 42978 === Results === Completed 42978 operations in a weighted-average of 10.00s (4,296.94 ops/s, 0.000 s/op) ```
1 parent 11ab9fe commit 0cdd118

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

sdk/core/Azure.Core/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
### Added
66
- `AzureSasCredential` and its respective policy.
77

8+
### Key Bug Fixes
9+
- Avoid a causing and ignoring an exception when setting network stream timeout on .NET Core
10+
811
## 1.7.0 (2020-12-14)
912

1013
### New Features

sdk/core/Azure.Core/perf/Azure.Core.Perf.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<ProjectReference Include="../../Azure.Core/src/Azure.Core.csproj" />
8+
<ProjectReference Condition="'$(AzureCoreVersion)' == ''" Include="../../Azure.Core/src/Azure.Core.csproj" />
9+
<PackageReference Condition="'$(AzureCoreVersion)' != ''" Include="Azure.Core" VersionOverride="$(AzureCoreVersion)" />
10+
</ItemGroup>
11+
<ItemGroup>
912
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj" />
10-
<ProjectReference Include="$(AzureCoreTestFramework)" />
1113
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" />
1214
</ItemGroup>
1315

sdk/core/Azure.Core/perf/DownloadHttpClientTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
using System.Net.Http;
77
using System.Threading;
88
using System.Threading.Tasks;
9-
using Azure.Core.Pipeline;
10-
using Azure.Identity;
119
using Azure.Test.Perf;
1210

1311
namespace Azure.Template.Perf

sdk/core/Azure.Core/perf/DownloadTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System;
54
using System.IO;
65
using System.Threading;
76
using System.Threading.Tasks;
7+
using Azure.Core;
88
using Azure.Core.Pipeline;
9-
using Azure.Identity;
109
using Azure.Test.Perf;
1110

1211
namespace Azure.Template.Perf
@@ -21,7 +20,7 @@ public class DownloadTest : PerfTest<DownloadTestOptions>
2120
public DownloadTest(DownloadTestOptions options) : base(options)
2221
{
2322
_server ??= InProcTestServer.CreateStaticResponse(options.Size);
24-
_pipeline ??= HttpPipelineBuilder.Build(new DefaultAzureCredentialOptions());
23+
_pipeline ??= HttpPipelineBuilder.Build(new TestClientOptions());
2524
}
2625

2726
public override void Run(CancellationToken cancellationToken)
@@ -48,5 +47,7 @@ public override void Dispose(bool disposing)
4847
base.Dispose(disposing);
4948
_server.Dispose();
5049
}
50+
51+
public class TestClientOptions: ClientOptions {}
5152
}
5253
}

sdk/core/Azure.Core/src/Pipeline/Internal/ReadTimeoutStream.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ private void UpdateReadTimeout()
138138
{
139139
try
140140
{
141-
_stream.ReadTimeout = (int) _readTimeout.TotalMilliseconds;
141+
if (_stream.CanTimeout)
142+
{
143+
_stream.ReadTimeout = (int) _readTimeout.TotalMilliseconds;
144+
}
142145
}
143146
catch
144147
{

sdk/core/Azure.Core/tests/ResponseBodyPolicyTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ public override int Read(byte[] buffer, int offset, int count)
201201
}
202202

203203
public override int ReadTimeout { get; set; }
204+
205+
public override bool CanTimeout { get; } = true;
204206
}
205207

206208
private class ReadTrackingStream : TestReadStream

0 commit comments

Comments
 (0)