Skip to content

Commit c0b1ecc

Browse files
Add the ShutdownTimeout to the Monitoring instance
1 parent c24ae96 commit c0b1ecc

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/ServiceControl.Monitoring/HostApplicationBuilderExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public static void AddServiceControlMonitoring(this IHostApplicationBuilder host
3939
var transportCustomization = TransportFactory.Create(transportSettings);
4040
transportCustomization.AddTransportForMonitoring(services, transportSettings);
4141

42+
services.Configure<HostOptions>(options => options.ShutdownTimeout = settings.ShutdownTimeout);
43+
4244
services.AddWindowsService();
4345

4446
services.AddSingleton(settings);

src/ServiceControl.Monitoring/Settings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public Settings(LoggingSettings loggingSettings = null, string transportType = n
3939
EndpointUptimeGracePeriod = TimeSpan.Parse(SettingsReader.Read(SettingsRootNamespace, "EndpointUptimeGracePeriod", "00:00:40"));
4040
MaximumConcurrencyLevel = SettingsReader.Read<int?>(SettingsRootNamespace, "MaximumConcurrencyLevel");
4141
ServiceControlThroughputDataQueue = SettingsReader.Read(SettingsRootNamespace, "ServiceControlThroughputDataQueue", "ServiceControl.ThroughputData");
42+
ShutdownTimeout = SettingsReader.Read(SettingsRootNamespace, "ShutdownTimeout", ShutdownTimeout);
4243

4344
AssemblyLoadContextResolver = static assemblyPath => new PluginAssemblyLoadContext(assemblyPath);
4445
}
@@ -68,6 +69,12 @@ public Settings(LoggingSettings loggingSettings = null, string transportType = n
6869

6970
public string ServiceControlThroughputDataQueue { get; set; }
7071

72+
// The default value is set to the maximum allowed time by the most
73+
// restrictive hosting platform, which is Linux containers. Linux
74+
// containers allow for a maximum of 10 seconds. We set it to 5 to
75+
// allow for cancellation and logging to take place
76+
public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5);
77+
7178
public TransportSettings ToTransportSettings()
7279
{
7380
var transportSettings = new TransportSettings

src/ServiceControlInstaller.Engine/Configuration/Monitoring/AppConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public void Save()
2222
settings.Set(SettingsList.TransportType, details.TransportPackage.Name, version);
2323
settings.Set(SettingsList.ErrorQueue, details.ErrorQueue);
2424

25+
// Windows services allow a maximum of 125 seconds when stopping a service.
26+
// When shutting down or restarting the OS we have no control over the
27+
// shutdown timeout. This is by the installer engine that is run _only_ on
28+
// Windows via SCMU or PowerShell
29+
settings.Set(SettingsList.ShutdownTimeout, "00:02:00", version);
30+
2531
// Retired settings
2632
settings.RemoveIfRetired(SettingsList.EndpointName, version);
2733

src/ServiceControlInstaller.Engine/Configuration/Monitoring/SettingsList.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,10 @@ public static class SettingsList
2121
public static SettingInfo LogPath = new() { Name = "Monitoring/LogPath" };
2222
public static SettingInfo TransportType = new() { Name = "Monitoring/TransportType" };
2323
public static SettingInfo ErrorQueue = new() { Name = "Monitoring/ErrorQueue" };
24+
public static SettingInfo ShutdownTimeout = new()
25+
{
26+
Name = "Monitoring/ShutdownTimeout",
27+
SupportedFrom = new SemanticVersion(6, 4, 1)
28+
};
2429
}
2530
}

0 commit comments

Comments
 (0)