fix(hns): preserve HRESULT in typed HNSError for downstream unwrapping#2800
Open
HarshalPatel1972 wants to merge 1 commit into
Open
fix(hns): preserve HRESULT in typed HNSError for downstream unwrapping#2800HarshalPatel1972 wants to merge 1 commit into
HarshalPatel1972 wants to merge 1 commit into
Conversation
Previously, hnsCall swallowed the specific ErrorCode/HRESULT returned by the Host Networking Service into a flat string. This prevented downstream callers (like containerd's CRI plugin) from using errors.As() to detect retryable or transient states (e.g., vSwitch restarting). This change introduces a strongly-typed HNSError that preserves the ErrorCode, allowing callers to correctly handle specific HNS failure modes. Signed-off-by: Harshal Patel <hp842484@gmail.com>
Comment on lines
+46
to
50
| Success bool | ||
| Error string | ||
| ErrorCode uint32 `json:"ErrorCode,omitempty"` | ||
| Output json.RawMessage | ||
| } |
Comment on lines
+48
to
+51
| return &HNSError{ | ||
| ErrorString: hnsresponse.Error, | ||
| ErrorCode: hnsresponse.ErrorCode, | ||
| } |
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 on lines
+5
to
+22
| import ( | ||
| "errors" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestHNSErrorPreservation(t *testing.T) { | ||
| // Mock the raw response | ||
| originalMock := hnsCallRawResponseMock | ||
| defer func() { hnsCallRawResponseMock = originalMock }() | ||
|
|
||
| hnsCallRawResponseMock = func(method, path, request string) (*hnsResponse, error) { | ||
| return &hnsResponse{ | ||
| Success: false, | ||
| Error: "vSwitch in transient state", | ||
| ErrorCode: 0x803b0013, // HCS_E_VMSWITCH_IN_TRANSIENT_STATE | ||
| }, nil | ||
| } | ||
|
|
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.
Problem
Currently,
hnsCallcollapses 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 underlyingErrorCode(HRESULT) returned by the API. Because of this, downstream consumers (specifically the containerd CRI plugin) cannot useerrors.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
HNSErrorstruct that implements the error interface and maps theErrorCodefield from the HNS JSON payload.hnsCallto return this typed error, ensuring the HRESULT is preserved and bubbled up the stack.Verification
TestHNSErrorPreservationto mock a failed HNS JSON response containing a transientErrorCode(e.g.,0x803b0013).errors.As()to unwrap the error and evaluate the specificErrorCode.