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

Async open improvements for NetTcp #4832

Merged
merged 3 commits into from
Jun 22, 2022
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
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</PropertyGroup>

<PropertyGroup>
<ScenarioTestTargetFrameworks>netcoreapp3.1;net5.0;net6.0</ScenarioTestTargetFrameworks>
<UnitTestTargetFrameworks>netcoreapp3.1;net5.0;net6.0</UnitTestTargetFrameworks>
<ScenarioTestTargetFrameworks>netcoreapp3.1;net6.0;net7.0</ScenarioTestTargetFrameworks>
<UnitTestTargetFrameworks>netcoreapp3.1;net6.0;net7.0</UnitTestTargetFrameworks>
<!-- This is the target framework version of the built tests picked up to send to Helix -->
<XUnitPublishTargetFramework>netcoreapp3.1</XUnitPublishTargetFramework>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions eng/SendToHelix.proj
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

<ItemGroup Condition="'$(TestJob)' == 'Windows' AND '$(RunAsInternal)'" >
<HelixTargetQueue Include="Windows.10.Amd64" />
<HelixTargetQueue Include="Debian.9.Amd64" />
<HelixTargetQueue Include="(Debian.11.Amd64.Open)ubuntu.2004.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-11-helix-amd64-20220511124750-0ece9b3" />
<HelixTargetQueue Include="RedHat.7.Amd64" />
</ItemGroup>

<ItemGroup Condition="'$(TestJob)' == 'Linux'" >
<HelixTargetQueue Include="Centos.7.Amd64.Open" />
<HelixTargetQueue Include="Debian.9.Amd64.Open" />
<HelixTargetQueue Include="(Debian.11.Amd64.Open)ubuntu.2004.amd64.open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-11-helix-amd64-20220511124750-0ece9b3" />
<HelixTargetQueue Include="RedHat.7.Amd64.Open" />
<HelixTargetQueue Include="SLES.12.Amd64.Open" />
<HelixTargetQueue Include="SLES.15.Amd64.Open" />
<HelixTargetQueue Include="Ubuntu.2004.Amd64.Open" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"runtimes": {
"dotnet": [
"3.1.5",
"5.0.4"
"6.0.5"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static string MachineName
{
try
{
s_machineName = Dns.GetHostEntryAsync(String.Empty).GetAwaiter().GetResult().HostName;
s_machineName = Dns.GetHostEntry(string.Empty).HostName;
}
catch (SocketException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,12 @@ protected internal override async Task OnOpenAsync(TimeSpan timeout)
IConnection connection;
try
{
connection = await _connectionPoolHelper.EstablishConnectionAsync(timeout);
// Execute socket connection code on either IO Thread (Windows) or our own new Thread (Linux)
// This is to mitigate sync over async Open calls from failing to progress when there's thread starvation.
using (TaskHelpers.RunTaskContinuationsOnOurThreads())
{
connection = await _connectionPoolHelper.EstablishConnectionAsync(timeout);
}
}
catch (TimeoutException exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,18 @@ private static async Task<IPAddress[]> GetIPAddressesAsync(Uri uri)
return new IPAddress[] { ipAddress };
}

if ("localhost".Equals(uri.DnsSafeHost, StringComparison.OrdinalIgnoreCase))
{
if (Socket.OSSupportsIPv6)
{
return new IPAddress[] { IPAddress.IPv6Loopback, IPAddress.Loopback };
}
else
{
return new IPAddress[] { IPAddress.Loopback };
}
}

IPAddress[] addresses = null;

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Net;
using System.Security.Principal;
using System.Threading.Tasks;
using System.Runtime;

namespace System.ServiceModel.Security
{
Expand Down Expand Up @@ -36,9 +37,14 @@ protected override SecurityToken GetTokenCore(TimeSpan timeout)
return _token;
}

internal override Task<SecurityToken> GetTokenCoreInternalAsync(TimeSpan timeout)
protected override IAsyncResult BeginGetTokenCore(TimeSpan timeout, AsyncCallback callback, object state)
{
return Task.FromResult<SecurityToken>(GetTokenCore(timeout));
return new CompletedAsyncResult<SecurityToken>(GetTokenCore(timeout), callback, state);
}

protected override SecurityToken EndGetTokenCore(IAsyncResult result)
{
return CompletedAsyncResult<SecurityToken>.End(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,46 +104,6 @@ public static void NegotiateStream_Http_AmbientCredentials()
}
}

[WcfFact]
[Condition(nameof(Windows_Authentication_Available),
nameof(Root_Certificate_Installed),
nameof(Ambient_Credentials_Available))]
[OuterLoop]
public static void NegotiateStream_Http_AmbientCredentialsForNet50()
{
string testString = "Hello";
ChannelFactory<IWcfService> factory = null;
IWcfService serviceProxy = null;

try
{
// *** SETUP *** \\
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
string spn = GetSPN().ToLowerInvariant().Replace("host", "HTTP");

factory = new ChannelFactory<IWcfService>(
binding,
new EndpointAddress(new Uri(Endpoints.Https_WindowsAuth_Address), new SpnEndpointIdentity(spn)));
serviceProxy = factory.CreateChannel();

// *** EXECUTE *** \\
string result = serviceProxy.Echo(testString);

// *** VALIDATE *** \\
Assert.Equal(testString, result);

// *** CLEANUP *** \\
((ICommunicationObject)serviceProxy).Close();
factory.Close();
}
finally
{
// *** ENSURE CLEANUP *** \\
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
}
}

[WcfFact]
[Condition(nameof(Windows_Authentication_Available),
nameof(Root_Certificate_Installed),
Expand Down