-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Q: Is it possible to trigger a drainstop & restart on configuration changes #10620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We don't have anything built in to wire these up. You can use the I believe you can use the As for restarting, there's nothing built-in to trigger a restart. You have a few options here. You could write code in your Program.Main to automatically restart the server if the shutdown is due to a configuration reload (you'll have to flow this information from the config reload callback yourself). Or you could have a "watchdog" process running that auto-restarts the server when it shuts down. |
Correct, with a default 5 second graceful shutdown timeout. That said, config has change detection and some components respond to it. What are you re-configuring? |
If you do still need to restart the app to react to config changes, and the default 5 second graceful shutdown timeout is insufficient, you can configure it. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/web-host?view=aspnetcore-2.2#shutdown-timeout |
I don't understand how that's different from your original question. |
@Tratcher the usecase/flow here is:-
my follow-up question is how can I hook into kestrel to identify how many requests are in-process or have been queued? and/or how long a request as been in-process/queued? I'm not sure of what the shutdown timeout would be? as all queued request must be processed prior to shutdown/restart. |
@Tratcher with regards to what is getting re-configured this could be anything from digital certificates to database connection string and anything in-between and therefore we opted for a process where a configuration change from a given source would restart the main webhost task. |
StopApplication handles this.
That's not something you need to worry about, Kestrel takes care of it.
Kestrel will do this, but it will abort requests after a given timeout (5 seconds by default). You can raise that timeout as needed, but I don't suggest disabling it. You wouldn't want a slow request to prevent your site from restarting indefinitely. |
@Tratcher hmmm, we don't what a restart to terminate any request; if a request is stuck or slow to complete, then manual intervention is required or we need some way of capturing these prior to killing the request and restarting. Q: is there any logging with regard to kestrel when a StopApplication is received ie. the status of the request queue time shutdown received etc. ? |
At this point I suggest trying StopApplication to see how well it works for you. |
@Tratcher Yes, thanks we are looking at this at present and will update soon with regards to our usecase |
@Tratcher I've got a simple application listening for configuration changes and calling the StopApplication as discussed, however the configuration change event is fired many times on a single simple change? which seems odd? are you aware of any issues around IChangeToken events ? simple log with a count outputs := WebApplicationWithRestart.Startup:Information: configuration change detected 1 |
That's a lot of changes 😁. What config source actually changed? A file? @HaoK ? |
@Tratcher I changed the appsettings.json logging level from within VS 2019 when running the code in debug |
Yeah the config change stuff is super noisy unfortunately, you can get notified many times for one actual file change, its due to using change tokens directly, we don't have any higher level concept that represents a 'file was updated' instead you get a bunch of file watcher notifications for changes that might not be the entire operation |
@HaoK is there any way to dial down these events via configuration or are these fix in code, also I'm wondering if its possible to only receive the event if a given section changes as opposed to a file/set of files loaded by the configuration builder ? |
Not really, the best thing to do to better control things might be to turn off the built in reload on change and manually watch for file changes and call reload on the config root yourself |
@HaoK can correct me if I'm wrong but I believe the chattiness here originates in the OS and how the app you use to edit the file writes to it. There really isn't much we can do. You could definitely add some logic to "debounce" the notifications though (i.e. wait a few seconds for the notifications to settle). |
Correct, these notifications are coming from the file system abstractions directly, there's nothing we can really do at the config layer for this https://github.com/aspnet/Extensions/blob/master/src/FileProviders/Abstractions/src/IFileProvider.cs#L32 |
We already added some throttling in the reload logic to prevent spamming reloads, but it doesn't look that that helps a ton: |
Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue. This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue! |
I'm looking for a way to drainstop a kestrel web host and restart the service via a configuration change; is this possible ? how would one inform the kestrel process to stop accepting request without impacting existing requests in process/queue?
The text was updated successfully, but these errors were encountered: