Skip to content

Commit dce70b3

Browse files
committed
remove ValueTask overrides on netcore2.1
1 parent 91c53e4 commit dce70b3

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@
308308
<Compile Include="Microsoft\Data\SqlClient\TdsParser.NetStandard.cs" />
309309
<Compile Include="Microsoft\Data\SqlClient\SNI\ConcurrentQueueSemaphore.NetStandard.cs" />
310310
<Compile Include="Microsoft\Data\SqlClient\SNI\SslOverTdsStream.NetStandard.cs" />
311+
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIStreams.Task.cs" />
311312
<Compile Include="Microsoft\Data\SqlClient\Reliability\SqlConfigurableRetryLogicManager.NetStandard.cs" />
312313
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIStreams.NetStandard.cs" />
313314
</ItemGroup>
@@ -354,7 +355,8 @@
354355
<Compile Include="Microsoft\Data\SqlClient\Reliability\SqlConfigurableRetryLogicManager.NetCoreApp.cs" />
355356
<Compile Include="Microsoft\Data\SqlClient\Reliability\SqlAppContextSwitchManager.NetCoreApp.cs" />
356357
<Compile Include="Microsoft\Data\SqlClient\SNI\ConcurrentQueueSemaphore.NetCoreApp.cs" />
357-
<Compile Include="Microsoft\Data\SqlClient\SNI\SNIStreams.NetCoreApp.cs" />
358+
<Compile Condition="$(TargetFramework.StartsWith('netcoreapp2.'))" Include="Microsoft\Data\SqlClient\SNI\SNIStreams.Task.cs" />
359+
<Compile Condition="!$(TargetFramework.StartsWith('netcoreapp2.'))" Include="Microsoft\Data\SqlClient\SNI\SNIStreams.ValueTask.cs" />
358360
</ItemGroup>
359361
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND '$(TargetGroup)' == 'netcoreapp' AND '$(BuildSimulator)' == 'true'">
360362
<Compile Include="Microsoft\Data\SqlClient\SimulatorEnclaveProvider.NetCoreApp.cs" />
@@ -799,6 +801,7 @@
799801
</ItemGroup>
800802
<ItemGroup>
801803
<Compile Include="Microsoft\Data\SqlClient\AAsyncCallContext.cs" />
804+
802805
<Compile Include="Resources\Strings.Designer.cs">
803806
<DesignTime>True</DesignTime>
804807
<AutoGen>True</AutoGen>

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/ConcurrentQueueSemaphore.NetStandard.cs

+16-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ internal sealed partial class ConcurrentQueueSemaphore
1111
{
1212
public Task WaitAsync(CancellationToken cancellationToken)
1313
{
14-
var tcs = new TaskCompletionSource<bool>();
15-
_queue.Enqueue(tcs);
16-
_semaphore.WaitAsync().ContinueWith(
17-
continuationAction: s_continuePop,
18-
state: _queue,
19-
cancellationToken: cancellationToken
20-
);
21-
return tcs.Task;
14+
// try sync wait with 0 which will not block to see if we need to do an async wait
15+
if (_semaphore.Wait(0, cancellationToken))
16+
{
17+
return Task.CompletedTask;
18+
}
19+
else
20+
{
21+
var tcs = new TaskCompletionSource<bool>();
22+
_queue.Enqueue(tcs);
23+
_semaphore.WaitAsync().ContinueWith(
24+
continuationAction: s_continuePop,
25+
state: _queue,
26+
cancellationToken: cancellationToken
27+
);
28+
return tcs.Task;
29+
}
2230
}
2331
}
2432
}

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIStreams.NetStandard.cs src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIStreams.Task.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System.Net.Security;
6-
using System.IO;
75
using System.Threading;
86
using System.Threading.Tasks;
9-
using System.Net.Sockets;
7+
108

119
namespace Microsoft.Data.SqlClient.SNI
1210
{
11+
// NetCore2.1:
12+
// DO NOT OVERRIDE ValueTask versions of ReadAsync and WriteAsync because the underlying SslStream implements them
13+
// by calling the Task versions which are already overridden meaning that if a caller uses Task WriteAsync this would
14+
// call ValueTask WriteAsync which then called TaskWriteAsync introducing a lock cycle and never return
15+
1316
internal sealed partial class SNISslStream
1417
{
1518
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIStreams.NetCoreApp.cs src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIStreams.ValueTask.cs

-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System.Net.Security;
6-
using System.IO;
75
using System.Threading;
86
using System.Threading.Tasks;
9-
using System.Net.Sockets;
107
using System;
118

129
namespace Microsoft.Data.SqlClient.SNI
1310
{
14-
1511
internal sealed partial class SNISslStream
1612
{
1713
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)