Add retries to selfhost deployer (#13063)
This commit is contained in:
parent
28b66b1dbd
commit
d19093ecbb
|
|
@ -1,4 +1,4 @@
|
||||||
// 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;
|
using System;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: (?<url>.*)$");
|
private static readonly Regex NowListeningRegex = new Regex(@"^\s*Now listening on: (?<url>.*)$");
|
||||||
private const string ApplicationStartedMessage = "Application started. Press Ctrl+C to shut down.";
|
private const string ApplicationStartedMessage = "Application started. Press Ctrl+C to shut down.";
|
||||||
|
|
||||||
|
private const int RetryCount = 5;
|
||||||
public Process HostProcess { get; private set; }
|
public Process HostProcess { get; private set; }
|
||||||
|
|
||||||
public SelfHostDeployer(DeploymentParameters deploymentParameters, ILoggerFactory loggerFactory)
|
public SelfHostDeployer(DeploymentParameters deploymentParameters, ILoggerFactory loggerFactory)
|
||||||
|
|
@ -55,23 +56,33 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
DotnetPublish();
|
DotnetPublish();
|
||||||
}
|
}
|
||||||
|
|
||||||
var hintUrl = TestUriHelper.BuildTestUri(
|
|
||||||
DeploymentParameters.ServerType,
|
|
||||||
DeploymentParameters.Scheme,
|
|
||||||
DeploymentParameters.ApplicationBaseUriHint,
|
|
||||||
DeploymentParameters.StatusMessagesEnabled);
|
|
||||||
|
|
||||||
// Launch the host process.
|
// Launch the host process.
|
||||||
var (actualUrl, hostExitToken) = await StartSelfHostAsync(hintUrl);
|
for (var i = 0; i < RetryCount; i++)
|
||||||
|
{
|
||||||
|
var hintUrl = TestUriHelper.BuildTestUri(
|
||||||
|
DeploymentParameters.ServerType,
|
||||||
|
DeploymentParameters.Scheme,
|
||||||
|
DeploymentParameters.ApplicationBaseUriHint,
|
||||||
|
DeploymentParameters.StatusMessagesEnabled);
|
||||||
|
var (actualUrl, hostExitToken) = await StartSelfHostAsync(hintUrl);
|
||||||
|
|
||||||
Logger.LogInformation("Application ready at URL: {appUrl}", actualUrl);
|
if (DeploymentParameters.ServerType == ServerType.HttpSys && hostExitToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
// Retry HttpSys deployments due to port conflicts.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
return new DeploymentResult(
|
Logger.LogInformation("Application ready at URL: {appUrl}", actualUrl);
|
||||||
LoggerFactory,
|
|
||||||
DeploymentParameters,
|
return new DeploymentResult(
|
||||||
applicationBaseUri: actualUrl.ToString(),
|
LoggerFactory,
|
||||||
contentRoot: DeploymentParameters.PublishApplicationBeforeDeployment ? DeploymentParameters.PublishedApplicationRootPath : DeploymentParameters.ApplicationPath,
|
DeploymentParameters,
|
||||||
hostShutdownToken: hostExitToken);
|
applicationBaseUri: actualUrl.ToString(),
|
||||||
|
contentRoot: DeploymentParameters.PublishApplicationBeforeDeployment ? DeploymentParameters.PublishedApplicationRootPath : DeploymentParameters.ApplicationPath,
|
||||||
|
hostShutdownToken: hostExitToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception($"Failed to start Self hosted application after {RetryCount} retries.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,8 +176,6 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
Logger.LogInformation("host process ID {pid} shut down", HostProcess.Id);
|
Logger.LogInformation("host process ID {pid} shut down", HostProcess.Id);
|
||||||
|
|
||||||
// If TrySetResult was called above, this will just silently fail to set the new state, which is what we want
|
// If TrySetResult was called above, this will just silently fail to set the new state, which is what we want
|
||||||
started.TrySetException(new Exception($"Command exited unexpectedly with exit code: {HostProcess.ExitCode}"));
|
|
||||||
|
|
||||||
TriggerHostShutdown(hostExitTokenSource);
|
TriggerHostShutdown(hostExitTokenSource);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -178,7 +187,6 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
{
|
{
|
||||||
Logger.LogError("Error occurred while starting the process. Exception: {exception}", ex.ToString());
|
Logger.LogError("Error occurred while starting the process. Exception: {exception}", ex.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HostProcess.HasExited)
|
if (HostProcess.HasExited)
|
||||||
{
|
{
|
||||||
Logger.LogError("Host process {processName} {pid} exited with code {exitCode} or failed to start.", startInfo.FileName, HostProcess.Id, HostProcess.ExitCode);
|
Logger.LogError("Host process {processName} {pid} exited with code {exitCode} or failed to start.", startInfo.FileName, HostProcess.Id, HostProcess.ExitCode);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
@ECHO OFF
|
||||||
|
SET RepoRoot=%~dp0..\..
|
||||||
|
%RepoRoot%\build.cmd -projects %~dp0**\*.*proj %*
|
||||||
Loading…
Reference in New Issue