Skip to content

Add async command execution for long-running SetPackage operations#621

Open
sigabrtv1-ui wants to merge 1 commit into
sonic-net:masterfrom
sigabrtv1-ui:feat/async-command-exec
Open

Add async command execution for long-running SetPackage operations#621
sigabrtv1-ui wants to merge 1 commit into
sonic-net:masterfrom
sigabrtv1-ui:feat/async-command-exec

Conversation

@sigabrtv1-ui
Copy link
Copy Markdown
Contributor

What I did

Added RunHostCommandAsync to pkg/exec and refactored the SetPackage handler to use it, so that long-running sonic-installer commands survive gRPC client disconnects.

How I did it

  1. pkg/exec/command.go: Added AsyncCommandHandle struct and RunHostCommandAsync() function that starts commands using a background context (decoupled from the caller). The timeout is still enforced via an internal context.
  2. pkg/gnoi/system/system.go: Refactored installPackage() and activatePackage() to use RunHostCommandAsync() instead of RunHostCommand(). Removed the ctx parameter since the command now manages its own lifecycle.
  3. Tests: Updated all tests and monkey-patching for the new signatures. Added NewCompletedAsyncHandle() helper for testing.

Why I did it

During DPU image installation via SetPackage, sonic-installer install can take several minutes. If the gRPC connection drops (e.g., due to keepalive issues), the previous synchronous RunHostCommand would be killed via context cancellation — potentially leaving the DPU in a broken state mid-install.

With async execution, the sonic-installer process continues to completion regardless of client disconnect.

How to verify it

  1. Pure package tests pass: make -f pure.mk test PACKAGES="pkg/exec pkg/gnoi/system" (96.1% coverage on system, 82.9% on exec)
  2. Full integration build and deb packaging verified in sonic-slave-bookworm container

Related: #619
Related: sonic-net/sonic-mgmt#23054

@mssonicbld
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@hdwhdw
Copy link
Copy Markdown
Contributor

hdwhdw commented Mar 18, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Add RunHostCommandAsync to pkg/exec which starts commands decoupled from
the caller's context. This is critical for SetPackage where sonic-installer
can run for minutes - if the gRPC client disconnects, the installation
continues safely in the background instead of being killed.

Changes:
- Add AsyncCommandHandle struct with Wait() and Done() methods
- Add RunHostCommandAsync() using background context with timeout
- Add NewCompletedAsyncHandle() helper for testing
- Refactor installPackage/activatePackage to use async execution
- Remove ctx parameter since the command manages its own lifecycle
- Update all tests for the new signatures

Related: sonic-net#619
Related: sonic-net/sonic-mgmt#23054

Signed-off-by: Dawei Huang <daweihuang@microsoft.com>
@sigabrtv1-ui sigabrtv1-ui force-pushed the feat/async-command-exec branch from 13cfcd1 to b3f7370 Compare March 19, 2026 16:51
@mssonicbld
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants