Skip to content

HttpSys GoAway #14522

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

Merged
merged 4 commits into from
Oct 1, 2019
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>

<PropertyGroup>
<!--Imitate IIS Express so we can use it's cert bindings-->
<PackageTags>214124cd-d05b-4309-9af9-9caa44b2b74a</PackageTags>
</PropertyGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Server.HttpSys" />
Expand Down
2 changes: 2 additions & 0 deletions src/Servers/HttpSys/samples/SelfHostServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static void Main(string[] args)
.UseHttpSys(options =>
{
options.UrlPrefixes.Add("http://localhost:5000");
// This is a pre-configured IIS express port. See the PackageTags in the csproj.
options.UrlPrefixes.Add("https://localhost:44319");
options.Authentication.Schemes = AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
})
Expand Down
1 change: 0 additions & 1 deletion src/Servers/HttpSys/src/NativeInterop/ComNetOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.Extensions.Internal;

namespace Microsoft.AspNetCore.Server.HttpSys
{
Expand Down
33 changes: 32 additions & 1 deletion src/Servers/HttpSys/src/RequestProcessing/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
Expand All @@ -18,6 +17,9 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{
internal sealed class Response
{
// Support is assumed until we get an error and turn it off.
private static bool SupportsGoAway = true;

private ResponseState _responseState;
private string _reasonPhrase;
private ResponseBody _nativeStream;
Expand Down Expand Up @@ -314,6 +316,31 @@ internal unsafe uint SendHeaders(HttpApiTypes.HTTP_DATA_CHUNK[] dataChunks,
asyncResult == null ? SafeNativeOverlapped.Zero : asyncResult.NativeOverlapped,
IntPtr.Zero);

// GoAway is only supported on later versions. Retry.
if (statusCode == ErrorCodes.ERROR_INVALID_PARAMETER
&& (flags & HttpApiTypes.HTTP_FLAGS.HTTP_SEND_RESPONSE_FLAG_GOAWAY) != 0)
{
flags &= ~HttpApiTypes.HTTP_FLAGS.HTTP_SEND_RESPONSE_FLAG_GOAWAY;
statusCode =
HttpApi.HttpSendHttpResponse(
RequestContext.Server.RequestQueue.Handle,
Request.RequestId,
(uint)flags,
pResponse,
&cachePolicy,
&bytesSent,
IntPtr.Zero,
0,
asyncResult == null ? SafeNativeOverlapped.Zero : asyncResult.NativeOverlapped,
IntPtr.Zero);

// Succeeded without GoAway, disable them.
if (statusCode != ErrorCodes.ERROR_INVALID_PARAMETER)
{
SupportsGoAway = false;
}
}

if (asyncResult != null &&
statusCode == ErrorCodes.ERROR_SUCCESS &&
HttpSysListener.SkipIOCPCallbackOnSuccess)
Expand Down Expand Up @@ -417,6 +444,10 @@ internal HttpApiTypes.HTTP_FLAGS ComputeHeaders(long writeCount, bool endOfReque
Headers.Append(HttpKnownHeaderNames.Connection, Constants.Close);
}
flags = HttpApiTypes.HTTP_FLAGS.HTTP_SEND_RESPONSE_FLAG_DISCONNECT;
if (responseCloseSet && requestVersion >= Constants.V2 && SupportsGoAway)
{
flags |= HttpApiTypes.HTTP_FLAGS.HTTP_SEND_RESPONSE_FLAG_GOAWAY;
}
}

Headers.IsReadOnly = true;
Expand Down
1 change: 1 addition & 0 deletions src/Shared/HttpSys/NativeInterop/HttpApiTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ internal enum HTTP_FLAGS : uint
HTTP_INITIALIZE_SERVER = 0x00000001,
HTTP_INITIALIZE_CBT = 0x00000004,
HTTP_SEND_RESPONSE_FLAG_OPAQUE = 0x00000040,
HTTP_SEND_RESPONSE_FLAG_GOAWAY = 0x00000100,
}

[Flags]
Expand Down