Propagate async signature higher into CLI host and Kubernetes paths#1235
Closed
jimmyp wants to merge 7 commits into
Conversation
583eb46 to
89077d9
Compare
GetDriveBytesUsingDu was blocking on ExecuteCommandAsync via .GetAwaiter().GetResult() because GetPathUsedBytes was called from a sync IMemoryCache.GetOrCreate factory. The chain is now fully async: GetDriveBytesUsingDuAsync → GetPathUsedBytesAsync (GetOrCreateAsync) → GetStorageInformationAsync → awaited by CreateScriptContainer EnsureDiskHasEnoughFreeSpace still blocks (it overrides a sync IOctopusFileSystem method called from config writes and script workspace readiness checks), but the sync boundary is now at the override where the constraint is obvious, not buried inside the du runner. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
AbstractCommand gets a StartAsync() virtual hook (defaults to calling
Start() so all existing sync commands need no changes). ServiceCommand
overrides StartAsync() instead of Start(), allowing the whole chain
below it to be properly async:
ServiceCommand.StartAsync()
-> IServiceConfigurator.Configure*Async()
-> LinuxServiceConfigurator / WindowsServiceConfigurator (async)
-> SystemCtlHelper.RunServiceCommandAsync()
-> await ExecuteCommandAsync()
Six .GetAwaiter().GetResult() calls removed (2 in SystemCtlHelper,
3 in LinuxServiceConfigurator, 1 in WindowsServiceConfigurator).
Replaced by one sync boundary in AbstractCommand's dispatcher where
the CLI host (OctopusProgram) requires a sync Action<ICommandRuntime>.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds StartAsync(string[], ICommandRuntime, OptionSet) to ICommand and ICommandHost.RunAsync(Func<ICommandRuntime, Task>, Action) to all four host implementations. OctopusProgram.Run() delegates to RunAsync(); Program.Main becomes async Task<int>. The single remaining sync boundary is AbstractCommand.Start(string[]...) which calls StartAsync(...).GetAwaiter().GetResult() — kept for backwards compatibility with any callers that hold an ICommand and call Start() synchronously, but OctopusProgram no longer goes through it. HelpCommand migrated to override StartAsync(string[]...) instead of Start(string[]...) for consistency. WindowsServiceHost.RunAsync uses Task.Run for ServiceBase.Run because that Windows API must block a thread by design. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ICommand.void Start(string[],...) and ICommandHost.void Run(Action,...) are now deleted — no production or test code calls them. All callers have been migrated to StartAsync / RunAsync. NoninteractiveHost.ManualResetEvent removed (only served the sync Run path). Three test fixtures (ServerCommsCommandTest, CheckServicesCommand Fixture, WatchdogCommandFixture) migrated to async Task tests using StartAsync and Assert.ThrowsAsync. Two Kubernetes integration test calls also updated to await StartAsync. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ICommandLineRunner.Execute → ExecuteAsync (Task<bool>). CommandLineRunner
now awaits ExecuteCommandAsync directly — no .GetAwaiter().GetResult().
Callers updated:
- ReviewAndRunScriptTabViewModel: already async Task<bool>; Rollback
becomes async Task RollbackAsync
- RunProcessDialog: ThreadPool.QueueUserWorkItem → Task.Run(async)
- SetupTentacleWizardModelBuilder test: NSubstitute mock updated
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Five commands (PollCommand, RegisterMachineCommandBase, ShowConfiguration, DeregisterMachine, DeregisterWorker) used a pre-existing pattern where protected Start() wrapped a private async Task StartAsync(). Now that AbstractCommand.StartAsync(string[],...) calls the protected virtual StartAsync() directly, they override that instead — no GetAwaiter needed. Also remove OctopusProgram.Run() (dead code — Main now calls RunAsync()). Remaining GetAwaiter().GetResult() sites are all pre-existing forced sync boundaries: IWritableKeyValueStore, IMachineKeyEncryptor (Kubernetes config), IOctopusFileSystem override, and WindowsServiceHost (ServiceBase.Run must block). All have been documented in prior commits or were pre-existing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
a1bc78f to
5f2ac43
Compare
Author
Author
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Stacks on top of EFT-3295 (the script abandonment PR) to propagate the async signature higher up the call stack — eliminating
.GetAwaiter().GetResult()calls that were left documented in the abandon PR.IKubernetesDirectoryInformationProvider.GetPathUsedBytesAsync,KubernetesPhysicalFileSystem.GetStorageInformationAsync, awaited fromKubernetesScriptPodCreatorIServiceConfigurator.Configure*Async,LinuxServiceConfigurator,WindowsServiceConfigurator,SystemCtlHelper.RunServiceCommandAsyncICommand.StartAsync,ICommandHost.RunAsync,Program.Mainbecomesasync Task<int>, syncStart/Runpaths removedICommandLineRunner— fully async viaExecuteAsync; WPF installer'sReviewAndRunScriptTabViewModelandRunProcessDialogupdatedTest plan
🤖 Generated with Claude Code