Merge pull request #1427 from dotnet-maestro-bot/merge/release/2.2-to-master
[automated] Merge branch 'release/2.2' => 'master'
This commit is contained in:
commit
d31bc9c064
|
|
@ -4,15 +4,21 @@
|
||||||
#include "DisconnectHandler.h"
|
#include "DisconnectHandler.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
#include "proxymodule.h"
|
#include "proxymodule.h"
|
||||||
|
#include "SRWExclusiveLock.h"
|
||||||
|
|
||||||
void DisconnectHandler::NotifyDisconnect()
|
void DisconnectHandler::NotifyDisconnect()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const auto module = m_pModule.exchange(nullptr);
|
std::unique_ptr<IREQUEST_HANDLER, IREQUEST_HANDLER_DELETER> module;
|
||||||
|
{
|
||||||
|
SRWExclusiveLock lock(m_handlerLock);
|
||||||
|
m_pHandler.swap(module);
|
||||||
|
}
|
||||||
|
|
||||||
if (module != nullptr)
|
if (module != nullptr)
|
||||||
{
|
{
|
||||||
module ->NotifyDisconnect();
|
module->NotifyDisconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
|
|
@ -27,7 +33,8 @@ void DisconnectHandler::CleanupStoredContext() noexcept
|
||||||
delete this;
|
delete this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisconnectHandler::SetHandler(ASPNET_CORE_PROXY_MODULE * module) noexcept
|
void DisconnectHandler::SetHandler(std::unique_ptr<IREQUEST_HANDLER, IREQUEST_HANDLER_DELETER> handler) noexcept
|
||||||
{
|
{
|
||||||
m_pModule = module;
|
SRWExclusiveLock lock(m_handlerLock);
|
||||||
|
handler.swap(m_pHandler);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <atomic>
|
|
||||||
|
#include <memory>
|
||||||
|
#include "irequesthandler.h"
|
||||||
|
|
||||||
class ASPNET_CORE_PROXY_MODULE;
|
class ASPNET_CORE_PROXY_MODULE;
|
||||||
|
|
||||||
|
|
@ -10,8 +12,9 @@ class DisconnectHandler final: public IHttpConnectionStoredContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DisconnectHandler()
|
DisconnectHandler()
|
||||||
: m_pModule(nullptr)
|
: m_pHandler(nullptr)
|
||||||
{
|
{
|
||||||
|
InitializeSRWLock(&m_handlerLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual
|
virtual
|
||||||
|
|
@ -27,9 +30,10 @@ public:
|
||||||
CleanupStoredContext() noexcept override;
|
CleanupStoredContext() noexcept override;
|
||||||
|
|
||||||
void
|
void
|
||||||
SetHandler(ASPNET_CORE_PROXY_MODULE * module) noexcept;
|
SetHandler(std::unique_ptr<IREQUEST_HANDLER, IREQUEST_HANDLER_DELETER> handler) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::atomic<ASPNET_CORE_PROXY_MODULE*> m_pModule;
|
SRWLOCK m_handlerLock {};
|
||||||
|
std::unique_ptr<IREQUEST_HANDLER, IREQUEST_HANDLER_DELETER> m_pHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,10 @@ ASPNET_CORE_PROXY_MODULE::ASPNET_CORE_PROXY_MODULE(HTTP_MODULE_ID moduleId, std:
|
||||||
|
|
||||||
ASPNET_CORE_PROXY_MODULE::~ASPNET_CORE_PROXY_MODULE()
|
ASPNET_CORE_PROXY_MODULE::~ASPNET_CORE_PROXY_MODULE()
|
||||||
{
|
{
|
||||||
|
// At this point m_pDisconnectHandler should be disconnected in
|
||||||
|
// HandleNotificationStatus
|
||||||
|
assert(m_pDisconnectHandler == nullptr);
|
||||||
|
|
||||||
if (m_pDisconnectHandler != nullptr)
|
if (m_pDisconnectHandler != nullptr)
|
||||||
{
|
{
|
||||||
m_pDisconnectHandler->SetHandler(nullptr);
|
m_pDisconnectHandler->SetHandler(nullptr);
|
||||||
|
|
@ -112,8 +116,6 @@ ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler(
|
||||||
FINISHED_IF_FAILED(moduleContainer->SetConnectionModuleContext(static_cast<IHttpConnectionStoredContext*>(disconnectHandler.release()), m_moduleId));
|
FINISHED_IF_FAILED(moduleContainer->SetConnectionModuleContext(static_cast<IHttpConnectionStoredContext*>(disconnectHandler.release()), m_moduleId));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pDisconnectHandler->SetHandler(this);
|
|
||||||
|
|
||||||
FINISHED_IF_FAILED(m_pApplicationManager->GetOrCreateApplicationInfo(
|
FINISHED_IF_FAILED(m_pApplicationManager->GetOrCreateApplicationInfo(
|
||||||
*pHttpContext,
|
*pHttpContext,
|
||||||
m_pApplicationInfo));
|
m_pApplicationInfo));
|
||||||
|
|
@ -121,6 +123,8 @@ ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler(
|
||||||
FINISHED_IF_FAILED(m_pApplicationInfo->CreateHandler(*pHttpContext, m_pHandler));
|
FINISHED_IF_FAILED(m_pApplicationInfo->CreateHandler(*pHttpContext, m_pHandler));
|
||||||
|
|
||||||
retVal = m_pHandler->OnExecuteRequestHandler();
|
retVal = m_pHandler->OnExecuteRequestHandler();
|
||||||
|
|
||||||
|
m_pDisconnectHandler->SetHandler(::ReferenceRequestHandler(m_pHandler.get()));
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
|
@ -141,7 +145,7 @@ Finished:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
return HandleNotificationStatus(retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
__override
|
__override
|
||||||
|
|
@ -156,18 +160,27 @@ ASPNET_CORE_PROXY_MODULE::OnAsyncCompletion(
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return m_pHandler->OnAsyncCompletion(
|
return HandleNotificationStatus(m_pHandler->OnAsyncCompletion(
|
||||||
pCompletionInfo->GetCompletionBytes(),
|
pCompletionInfo->GetCompletionBytes(),
|
||||||
pCompletionInfo->GetCompletionStatus());
|
pCompletionInfo->GetCompletionStatus()));
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
OBSERVE_CAUGHT_EXCEPTION();
|
OBSERVE_CAUGHT_EXCEPTION();
|
||||||
return RQ_NOTIFICATION_FINISH_REQUEST;
|
return HandleNotificationStatus(RQ_NOTIFICATION_FINISH_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASPNET_CORE_PROXY_MODULE::NotifyDisconnect() const
|
REQUEST_NOTIFICATION_STATUS ASPNET_CORE_PROXY_MODULE::HandleNotificationStatus(REQUEST_NOTIFICATION_STATUS status) noexcept
|
||||||
{
|
{
|
||||||
m_pHandler->NotifyDisconnect();
|
if (status != RQ_NOTIFICATION_PENDING)
|
||||||
|
{
|
||||||
|
if (m_pDisconnectHandler != nullptr)
|
||||||
|
{
|
||||||
|
m_pDisconnectHandler->SetHandler(nullptr);
|
||||||
|
m_pDisconnectHandler = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,8 @@ class ASPNET_CORE_PROXY_MODULE : NonCopyable, public CHttpModule
|
||||||
IHttpCompletionInfo * pCompletionInfo
|
IHttpCompletionInfo * pCompletionInfo
|
||||||
) override;
|
) override;
|
||||||
|
|
||||||
void
|
REQUEST_NOTIFICATION_STATUS
|
||||||
NotifyDisconnect() const;
|
HandleNotificationStatus(REQUEST_NOTIFICATION_STATUS status) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<APPLICATION_MANAGER> m_pApplicationManager;
|
std::shared_ptr<APPLICATION_MANAGER> m_pApplicationManager;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "SRWExclusiveLock.h"
|
#include "SRWExclusiveLock.h"
|
||||||
|
|
||||||
SRWExclusiveLock::SRWExclusiveLock(const SRWLOCK& lock)
|
SRWExclusiveLock::SRWExclusiveLock(const SRWLOCK& lock) noexcept
|
||||||
: m_lock(lock)
|
: m_lock(lock)
|
||||||
{
|
{
|
||||||
AcquireSRWLockExclusive(const_cast<SRWLOCK*>(&m_lock));
|
AcquireSRWLockExclusive(const_cast<SRWLOCK*>(&m_lock));
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
class SRWExclusiveLock
|
class SRWExclusiveLock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SRWExclusiveLock(const SRWLOCK& lock);
|
SRWExclusiveLock(const SRWLOCK& lock) noexcept;
|
||||||
~SRWExclusiveLock();
|
~SRWExclusiveLock();
|
||||||
private:
|
private:
|
||||||
const SRWLOCK& m_lock;
|
const SRWLOCK& m_lock;
|
||||||
|
|
|
||||||
|
|
@ -54,3 +54,9 @@ struct IREQUEST_HANDLER_DELETER
|
||||||
application->DereferenceRequestHandler();
|
application->DereferenceRequestHandler();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline std::unique_ptr<IREQUEST_HANDLER, IREQUEST_HANDLER_DELETER> ReferenceRequestHandler(IREQUEST_HANDLER* handler)
|
||||||
|
{
|
||||||
|
handler->ReferenceRequestHandler();
|
||||||
|
return std::unique_ptr<IREQUEST_HANDLER, IREQUEST_HANDLER_DELETER>(handler);
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
||||||
|
using Microsoft.AspNetCore.Testing.xunit;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
|
{
|
||||||
|
[Collection(PublishedSitesCollection.Name)]
|
||||||
|
public class ClientDisconnectStressTests: FunctionalTestsBase
|
||||||
|
{
|
||||||
|
private readonly PublishedSitesFixture _fixture;
|
||||||
|
|
||||||
|
public ClientDisconnectStressTests(PublishedSitesFixture fixture)
|
||||||
|
{
|
||||||
|
_fixture = fixture;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ConditionalTheory]
|
||||||
|
[InlineData(HostingModel.InProcess)]
|
||||||
|
[InlineData(HostingModel.OutOfProcess)]
|
||||||
|
public async Task ClientDisconnectStress(HostingModel hostingModel)
|
||||||
|
{
|
||||||
|
var site = await StartAsync(_fixture.GetBaseDeploymentParameters(hostingModel));
|
||||||
|
var maxRequestSize = 1000;
|
||||||
|
var blockSize = 40;
|
||||||
|
var random = new Random();
|
||||||
|
async Task RunRequests()
|
||||||
|
{
|
||||||
|
using (var connection = new TestConnection(site.HttpClient.BaseAddress.Port))
|
||||||
|
{
|
||||||
|
await connection.Send(
|
||||||
|
"POST /ReadAndFlushEcho HTTP/1.1",
|
||||||
|
$"Content-Length: {maxRequestSize}",
|
||||||
|
"Host: localhost",
|
||||||
|
"Connection: close",
|
||||||
|
"",
|
||||||
|
"");
|
||||||
|
|
||||||
|
var disconnectAfter = random.Next(maxRequestSize);
|
||||||
|
var data = new byte[blockSize];
|
||||||
|
for (int i = 0; i < disconnectAfter / blockSize; i++)
|
||||||
|
{
|
||||||
|
await connection.Stream.WriteAsync(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Task> tasks = new List<Task>();
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
tasks.Add(Task.Run(RunRequests));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.WhenAll(tasks);
|
||||||
|
|
||||||
|
StopServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities;
|
using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities;
|
||||||
|
|
@ -41,19 +40,19 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConditionalTheory]
|
[ConditionalTheory]
|
||||||
[InlineData("ConsoleErrorWrite")]
|
[InlineData("ConsoleErrorWriteStartServer")]
|
||||||
[InlineData("ConsoleWrite")]
|
[InlineData("ConsoleWriteStartServer")]
|
||||||
public async Task CheckStdoutLoggingToPipeWithFirstWrite(string path)
|
public async Task CheckStdoutLoggingToPipeWithFirstWrite(string path)
|
||||||
{
|
{
|
||||||
var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true);
|
var deploymentParameters = _fixture.GetBaseDeploymentParameters(publish: true);
|
||||||
|
|
||||||
var firstWriteString = path + path;
|
var firstWriteString = "TEST MESSAGE";
|
||||||
|
|
||||||
deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_INPROCESS_INITIAL_WRITE"] = firstWriteString;
|
deploymentParameters.TransformArguments((a, _) => $"{a} {path}");
|
||||||
|
|
||||||
var deploymentResult = await DeployAsync(deploymentParameters);
|
var deploymentResult = await DeployAsync(deploymentParameters);
|
||||||
|
|
||||||
await Helpers.AssertStarts(deploymentResult, path);
|
await Helpers.AssertStarts(deploymentResult);
|
||||||
|
|
||||||
StopServer();
|
StopServer();
|
||||||
|
|
||||||
|
|
@ -61,7 +60,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
{
|
{
|
||||||
// We can't read stdout logs from IIS as they aren't redirected.
|
// We can't read stdout logs from IIS as they aren't redirected.
|
||||||
Assert.Contains(TestSink.Writes, context => context.Message.Contains(firstWriteString));
|
Assert.Contains(TestSink.Writes, context => context.Message.Contains(firstWriteString));
|
||||||
Assert.Contains(TestSink.Writes, context => context.Message.Contains("TEST MESSAGE"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities;
|
using Microsoft.AspNetCore.Server.IIS.FunctionalTests.Utilities;
|
||||||
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
||||||
|
|
|
||||||
|
|
@ -79,31 +79,33 @@ namespace TestSite
|
||||||
host.Run();
|
host.Run();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "ConsoleErrorWriteStartServer":
|
||||||
|
Console.Error.WriteLine("TEST MESSAGE");
|
||||||
|
return StartServer();
|
||||||
|
case "ConsoleWriteStartServer":
|
||||||
|
Console.WriteLine("TEST MESSAGE");
|
||||||
|
return StartServer();
|
||||||
default:
|
default:
|
||||||
{
|
return StartServer();
|
||||||
|
|
||||||
var envVariable = Environment.GetEnvironmentVariable("ASPNETCORE_INPROCESS_INITIAL_WRITE");
|
|
||||||
if (!string.IsNullOrEmpty(envVariable))
|
|
||||||
{
|
|
||||||
Console.WriteLine(envVariable);
|
|
||||||
Console.Error.WriteLine(envVariable);
|
|
||||||
}
|
|
||||||
|
|
||||||
var host = new WebHostBuilder()
|
|
||||||
.ConfigureLogging((_, factory) =>
|
|
||||||
{
|
|
||||||
factory.AddConsole();
|
|
||||||
factory.AddFilter("Console", level => level >= LogLevel.Information);
|
|
||||||
})
|
|
||||||
.UseIIS()
|
|
||||||
.UseStartup<Startup>()
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
host.Run();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 12;
|
return 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int StartServer()
|
||||||
|
{
|
||||||
|
var host = new WebHostBuilder()
|
||||||
|
.ConfigureLogging((_, factory) =>
|
||||||
|
{
|
||||||
|
factory.AddConsole();
|
||||||
|
factory.AddFilter("Console", level => level >= LogLevel.Information);
|
||||||
|
})
|
||||||
|
.UseIIS()
|
||||||
|
.UseStartup<Startup>()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
host.Run();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -324,6 +324,17 @@ namespace TestSite
|
||||||
result = await ctx.Request.Body.ReadAsync(readBuffer, 0, readBuffer.Length);
|
result = await ctx.Request.Body.ReadAsync(readBuffer, 0, readBuffer.Length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private async Task ReadAndFlushEcho(HttpContext ctx)
|
||||||
|
{
|
||||||
|
var readBuffer = new byte[4096];
|
||||||
|
var result = await ctx.Request.Body.ReadAsync(readBuffer, 0, readBuffer.Length);
|
||||||
|
while (result != 0)
|
||||||
|
{
|
||||||
|
await ctx.Response.WriteAsync(Encoding.UTF8.GetString(readBuffer, 0, result));
|
||||||
|
await ctx.Response.Body.FlushAsync();
|
||||||
|
result = await ctx.Request.Body.ReadAsync(readBuffer, 0, readBuffer.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task ReadAndWriteEchoLines(HttpContext ctx)
|
private async Task ReadAndWriteEchoLines(HttpContext ctx)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue