Skip to content

Commit 512209d

Browse files
Avoid IISHttpServer close race on construction (#60399)
1 parent 8b11341 commit 512209d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Servers/IIS/IIS/src/Core/IISHttpServer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal sealed class IISHttpServer : IServer
2828
private readonly IISServerOptions _options;
2929
private readonly IISNativeApplication _nativeApplication;
3030
private readonly ServerAddressesFeature _serverAddressesFeature;
31-
private readonly string? _virtualPath;
31+
private string? _virtualPath;
3232

3333
private readonly TaskCompletionSource _shutdownSignal = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
3434
private bool? _websocketAvailable;
@@ -69,8 +69,6 @@ ILogger<IISHttpServer> logger
6969
_logger = logger;
7070
_options = options.Value;
7171
_serverAddressesFeature = new ServerAddressesFeature();
72-
var iisConfigData = NativeMethods.HttpGetApplicationProperties();
73-
_virtualPath = iisConfigData.pwzVirtualApplicationPath;
7472

7573
if (_options.ForwardWindowsAuthentication)
7674
{
@@ -106,6 +104,9 @@ public unsafe Task StartAsync<TContext>(IHttpApplication<TContext> application,
106104
(IntPtr)_httpServerHandle,
107105
(IntPtr)_httpServerHandle);
108106

107+
var iisConfigData = NativeMethods.HttpGetApplicationProperties();
108+
_virtualPath = iisConfigData.pwzVirtualApplicationPath;
109+
109110
_serverAddressesFeature.Addresses = _options.ServerAddresses;
110111

111112
return Task.CompletedTask;

src/Servers/IIS/IIS/test/IISExpress.FunctionalTests/InProcess/AppOfflineIISExpressTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public AppOfflineIISExpressTests(PublishedSitesFixture fixture) : base(fixture)
1919
}
2020

2121
[ConditionalFact]
22+
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/60482")]
2223
public async Task AppOfflineDroppedWhileSiteStarting_SiteShutsDown_InProcess()
2324
{
2425
// This test often hits a race between debug logging and stdout redirection closing the handle
@@ -55,8 +56,8 @@ public async Task AppOfflineDroppedWhileSiteStarting_SiteShutsDown_InProcess()
5556
{
5657
// For IISExpress, we need to catch the exception because IISExpress will not restart a process if it crashed.
5758
// RemoveAppOffline will fail due to a bad request exception as the server is down.
58-
Assert.Contains(TestSink.Writes, context => context.Message.Contains("Drained all requests, notifying managed."));
5959
deploymentResult.AssertWorkerProcessStop();
60+
Assert.Contains(TestSink.Writes, context => context.Message.Contains("Drained all requests, notifying managed."));
6061
return;
6162
}
6263
}

0 commit comments

Comments
 (0)