Should ShutdownTimeout
be set to shorter value then the *host* shutdown period?
#113127
Unanswered
ramonsmits
asked this question in
Q&A
Replies: 0 comments 1 reply
-
This doesn't look related to the .NET container images. I am transferring this discussion to dotnet/runtime. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
According to the inline docs Shut
Source:
runtime/src/libraries/Microsoft.Extensions.Hosting/src/HostOptions.cs
Line 24 in 80aa709
The webhost:
https://github.com/dotnet/aspnetcore/blob/1f82fa558dd7afb0ac94a43c7b80f40499bad98c/src/Hosting/Hosting/src/Internal/WebHost.cs#L290
runtime/src/libraries/Microsoft.Extensions.Hosting/src/Internal/Host.cs
Line 224 in 6d344b3
What I see happening is that this value is often set to the duration that the host allows for graceful termination.
For example, the default is 30 seconds which is aligned with the windows server default.
However, what is the point of setting this to the same value as the hosting environment as usually this results in process termination?
To me it seems that
ShutdownTimeout
should be set to for example 25 seconds. After 25 seconds, shutdown is cancelled and now 5 seconds are remaining for an ungraceful shutdown until the host will terminate the process.As on Windows I think the default duration is 20 seconds, should this value then be set to 15 seconds?
WindowsServiceLifetime and RequestAdditionalTime
I've also looked at the
WindowsServiceLifetime
. It has some delay logic that usesShutdownTimeout
in theOnStop
andOnShutdown
. However, I expected it to invokeServiceBase.RequestAdditionalTime
which it does not. I've searched the whole repo onRequestAdditionalTime
and it isn't used.Meaning, you can't set
ShutdownTimeout
to for example 2 minutes and expect Windows Server to allow your application longer to its maximum default of 125 seconds becauseRequestAdditionalTime
isn't invoked.Source: https://github.com/dotnet/runtime/blob/v9.0.2/src/libraries/Microsoft.Extensions.Hosting.WindowsServices/src/WindowsServiceLifetime.cs
This is also mentioned at:
Unfortunately, that issue was incorectly marked as resolved.
It does list alternatives:
WindowsServiceLifetime
, and overrideOnStop
andOnShutdown
and setRequestAdditionalTime
toShutdownTimeout + TimeSpan.FromSeconds(5)
to allow for a 5 second cancellation period.IHostLifetime
, cast it toWindowsServiceLifetime
:((WindowsServiceLifetime)hostLifetime).RequestAdditionalTime(..)
So in short:
ShutdownTimeout
30 seconds while in most environments its shorter (windows service 20 seconds, docker 10 seconds).ShutdownTimeout
to the same value, as that will align process terminination with cancellation. Meaning cooperative cancellation likely will not be executed.WindowsServiceLifetime
invokingRequestAdditionalTime
that included a short timespan (5 seconds?) to allow cooperative cancellation?Beta Was this translation helpful? Give feedback.
All reactions