Skip to content

fix(hns): preserve HRESULT in typed HNSError for downstream unwrapping#2800

Open
HarshalPatel1972 wants to merge 1 commit into
microsoft:mainfrom
HarshalPatel1972:patch-hcsshim
Open

fix(hns): preserve HRESULT in typed HNSError for downstream unwrapping#2800
HarshalPatel1972 wants to merge 1 commit into
microsoft:mainfrom
HarshalPatel1972:patch-hcsshim

Conversation

@HarshalPatel1972

@HarshalPatel1972 HarshalPatel1972 commented Jun 30, 2026

Copy link
Copy Markdown

Problem

Currently, hnsCall collapses the JSON failure response from the Host Networking Service into a flat string (fmt.Errorf("hns failed with error : %s", hnsresponse.Error)). This strips the underlying ErrorCode (HRESULT) returned by the API. Because of this, downstream consumers (specifically the containerd CRI plugin) cannot use errors.As() to inspect the error type. This leads to severe downstream bugs—such as containerd hanging indefinitely during transient vSwitch states, because it cannot identify the specific HRESULT that should trigger its retry/backoff logic.

Fix

  • Introduced a strongly-typed HNSError struct that implements the error interface and maps the ErrorCode field from the HNS JSON payload.
  • Modified hnsCall to return this typed error, ensuring the HRESULT is preserved and bubbled up the stack.

Verification

  • Added TestHNSErrorPreservation to mock a failed HNS JSON response containing a transient ErrorCode (e.g., 0x803b0013).
  • Verified that downstream callers can successfully use standard errors.As() to unwrap the error and evaluate the specific ErrorCode.

@HarshalPatel1972 HarshalPatel1972 requested a review from a team as a code owner June 30, 2026 13:11
Copilot AI review requested due to automatic review settings June 30, 2026 13:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment on lines +46 to 50
Success bool
Error string
ErrorCode uint32 `json:"ErrorCode,omitempty"`
Output json.RawMessage
}
Comment thread internal/hns/hnsfuncs.go
Comment on lines +48 to +51
return &HNSError{
ErrorString: hnsresponse.Error,
ErrorCode: hnsresponse.ErrorCode,
}
Comment thread internal/hns/hnsfuncs.go
Comment on lines +31 to +38
type HNSError struct {
ErrorString string
ErrorCode uint32
}

func (e *HNSError) Error() string {
return fmt.Sprintf("hns failed with error : %s", e.ErrorString)
}
Comment thread internal/hns/hnsfuncs_test.go
Previously, hnsCall swallowed the specific ErrorCode/HRESULT returned by the Host Networking Service into a flat string. This prevented downstream callers from using errors.As() to detect retryable states.

This change introduces a strongly-typed HNSError that preserves the ErrorCode. It correctly handles signed decoding for negative HRESULT payloads and re-exports the type in the public hcsshim package.

Signed-off-by: Harshal Patel <hp842484@gmail.com>
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.

2 participants