-
Notifications
You must be signed in to change notification settings - Fork 28
fix(daemon): bound the daemon-stop session drain and give CLI stop kill headroom #1673
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
Merged
Aaronontheweb
merged 1 commit into
netclaw-dev:dev
from
Aaronontheweb:fix/shutdown-drain-and-kill-budgets
Jul 16, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Netclaw.Daemon.Tests/DaemonShutdownConfigurationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="DaemonShutdownConfigurationTests.cs" company="Petabridge, LLC"> | ||
| // Copyright (C) 2026 - 2026 Petabridge, LLC <https://petabridge.com> | ||
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
| using Akka.Configuration; | ||
| using Netclaw.Configuration; | ||
| using Xunit; | ||
|
|
||
| namespace Netclaw.Daemon.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Tests for <see cref="DaemonShutdownConfiguration.BuildCoordinatedShutdownHocon"/>, which | ||
| /// replaced the inline HOCON literal Program.cs used to prepend a hardcoded 200s | ||
| /// before-service-unbind phase timeout (netclaw-dev/netclaw#1664, #1665). Proves the emitted | ||
| /// HOCON tracks whatever <see cref="DaemonConfig.GracefulShutdownBudget"/> resolves to instead | ||
| /// of drifting back to a literal that could disagree with the daemon-stop drain's own bound. | ||
| /// </summary> | ||
| public sealed class DaemonShutdownConfigurationTests | ||
| { | ||
| [Theory] | ||
| [InlineData(200, 200)] | ||
| [InlineData(90, 90)] | ||
| public void BuildCoordinatedShutdownHocon_interpolates_the_given_budget_in_seconds( | ||
| int budgetSeconds, int expectedPhaseTimeoutSeconds) | ||
| { | ||
| var hocon = DaemonShutdownConfiguration.BuildCoordinatedShutdownHocon(TimeSpan.FromSeconds(budgetSeconds)); | ||
|
|
||
| var config = ConfigurationFactory.ParseString(hocon); | ||
|
|
||
| Assert.Equal(TimeSpan.FromSeconds(expectedPhaseTimeoutSeconds), | ||
| config.GetTimeSpan("akka.coordinated-shutdown.phases.before-service-unbind.timeout")); | ||
| Assert.False(config.GetBoolean("akka.coordinated-shutdown.exit-clr")); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BuildCoordinatedShutdownHocon_tracks_DaemonConfig_GracefulShutdownBudget() | ||
| { | ||
| var hocon = DaemonShutdownConfiguration.BuildCoordinatedShutdownHocon(DaemonConfig.GracefulShutdownBudget); | ||
|
|
||
| var config = ConfigurationFactory.ParseString(hocon); | ||
|
|
||
| Assert.Equal( | ||
| DaemonConfig.GracefulShutdownBudget, | ||
| config.GetTimeSpan("akka.coordinated-shutdown.phases.before-service-unbind.timeout")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="DaemonShutdownConfiguration.cs" company="Petabridge, LLC"> | ||
| // Copyright (C) 2026 - 2026 Petabridge, LLC <https://petabridge.com> | ||
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
| using Netclaw.Configuration; | ||
|
|
||
| namespace Netclaw.Daemon; | ||
|
|
||
| /// <summary> | ||
| /// Builds the Akka CoordinatedShutdown HOCON override that bounds the daemon's session-drain | ||
| /// phase. Extracted into its own testable method (rather than an inline string literal in | ||
| /// Program.cs's top-level statements) so a unit test can assert the interpolated timeout | ||
| /// tracks <see cref="DaemonConfig.GracefulShutdownBudget"/> instead of drifting back to a | ||
| /// hardcoded literal (see <see cref="DaemonConfig.GracefulShutdownBudget"/> remarks for why | ||
| /// that drift is the exact class of bug behind netclaw-dev/netclaw#1664 and #1665). | ||
| /// </summary> | ||
| internal static class DaemonShutdownConfiguration | ||
| { | ||
| /// <summary> | ||
| /// Coordinated-shutdown HOCON: disables the CLR-exit side effect (the daemon's own | ||
| /// restart loop owns process lifetime, not CoordinatedShutdown) and sizes the | ||
| /// <c>before-service-unbind</c> phase — where session draining | ||
| /// (<c>SessionDrainHelper.DrainAsync</c>) actually runs — to <paramref name="gracefulShutdownBudget"/>. | ||
| /// </summary> | ||
| public static string BuildCoordinatedShutdownHocon(TimeSpan gracefulShutdownBudget) => $$""" | ||
| akka.coordinated-shutdown { | ||
| exit-clr = off | ||
| phases.before-service-unbind.timeout = {{(int)gracefulShutdownBudget.TotalSeconds}}s | ||
| } | ||
| """; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM