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
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) | ||
| } |
651863d to
5846ae8
Compare
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>
5846ae8 to
ac52173
Compare
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.