Skip to content

Fix/2769 update node status - #2770

Open
WorrierKhushal wants to merge 6 commits into
openyurtio:masterfrom
WorrierKhushal:fix/2769-update-node-status
Open

Fix/2769 update node status#2770
WorrierKhushal wants to merge 6 commits into
openyurtio:masterfrom
WorrierKhushal:fix/2769-update-node-status

Conversation

@WorrierKhushal

Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:

Background

In pkg/yurthub/proxy/autonomy/autonomy.go, the AutonomyProxy handles node status updates via the updateNodeStatus method, which utilizes a retry loop (nodeStatusUpdateRetry) to ensure node conditions are synchronized reliably between edge components and storage/cloud managers.

The Bug

When intermittent or persistent errors occur during the retry loop, the code previously handled them by logging via klog.ErrorS and continuing or breaking out of the loop based on specific error types (such as ErrDirectClientMgr).

However, if the loop completed with a non-nil retNode reference (captured from a prior successful iteration or an intermediate partial fetch), the function fell through and returned retNode, nil — completely discarding the accumulated error state.

// Before (simplified logic)
for i := 0; i < nodeStatusUpdateRetry; i++ {
node, err = ap.tryUpdateNodeConditions(i, req)
if node != nil {
retNode = node
}
if errors.Is(err, ErrDirectClientMgr) {
break
} else if err != nil {
klog.ErrorS(err, "Error getting or updating node status, will retry")
} else {
return retNode, nil
}
}
if retNode == nil {
return nil, fmt.Errorf("failed to get node")
}
klog.ErrorS(err, "failed to update node autonomy status")
return retNode, nil // <--- Returns stale node with nil error even when persistent errors occurred!

Impact

Callers (such as ServeHTTP and downstream proxy consumers) received a nil error alongside a potentially stale or un-updated node object. This silently swallowed critical storage and synchronization failures, leading the system to proceed under the false assumption that node autonomy state was successfully updated when it actually failed. This created subtle state divergence in edge node autonomy management.

The Fix

  1. Introduced an explicit hadError := false tracking flag prior to entering the retry loop.
  2. Set hadError = true whenever a non-retryable/persistent error occurs within the loop attempts.
  3. Added a post-loop check: if hadError is true, the function now correctly rejects the operation by returning an appropriate error (fmt.Errorf("failed to update node autonomy status after retries")) instead of blindly returning retNode, nil.

// After (fixed logic)
hadError := false
for i := 0; i < nodeStatusUpdateRetry; i++ {
node, err = ap.tryUpdateNodeConditions(i, req)
if node != nil {
retNode = node
}
if errors.Is(err, ErrDirectClientMgr) {
break
} else if err != nil {
hadError = true
klog.ErrorS(err, "Error getting or updating node status, will retry")
} else {
return retNode, nil
}
}
if retNode == nil {
return nil, fmt.Errorf("failed to get node")
}
if hadError {
return nil, fmt.Errorf("failed to update node autonomy status after retries")
}
klog.ErrorS(err, "failed to update node autonomy status")
return retNode, nil

Test Coverage

  • Added a dedicated unit test in autonomy_test.go simulating persistent errors across retry iterations where an intermediate node is present, verifying that updateNodeStatus correctly surfaces the error rather than silently returning retNode, nil.
  • Ensured all existing autonomy proxy tests continue to pass without regression.

Which issue(s) this PR fixes:
Fixes #2769

Special notes for your reviewer:

  • go test -v ./pkg/yurthub/proxy/autonomy/... — all existing and new tests pass cleanly.
  • go build ./pkg/yurthub/proxy/... — builds without errors.
  • go vet ./pkg/yurthub/proxy/autonomy/... — zero warnings or issues.
  • Confirmed updateNodeStatus is called exclusively from AutonomyProxy.ServeHTTP; downstream clients will now receive proper error propagation enabling appropriate fallback or retry behavior.

Does this PR introduce a user-facing change?
NONE

@WorrierKhushal
WorrierKhushal requested a review from a team as a code owner August 26, 2026 14:21
@sonarqubecloud

Copy link
Copy Markdown

@WorrierKhushal

Copy link
Copy Markdown
Contributor Author

Hi @zyjhtangtang @luc99hen Sir ,

I just opened a PR for issue #2769 to fix the silent error suppression issue in updateNodeStatus.

This update ensures that persistent errors during node condition updates are properly returned to callers instead of falling back to a stale node, and it includes a new unit test for coverage. All local tests, builds, and vet checks pass successfully.

I would appreciate your feedback when you have a moment. Thank you for your time!

@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.32184% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.23%. Comparing base (ddf22f7) to head (8ca72e8).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
pkg/yurthub/util/dumpstack.go 0.00% 20 Missing ⚠️
pkg/yurthub/configuration/manager.go 33.33% 5 Missing and 1 partial ⚠️
pkg/yurthub/filter/manager/manager.go 89.36% 3 Missing and 2 partials ⚠️
...ub/proxy/multiplexer/testing/fake_filtermanager.go 0.00% 4 Missing ⚠️
cmd/yurthub/app/config/config.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2770      +/-   ##
==========================================
+ Coverage   46.20%   46.23%   +0.03%     
==========================================
  Files         405      405              
  Lines       27540    27632      +92     
==========================================
+ Hits        12724    12777      +53     
- Misses      13649    13677      +28     
- Partials     1167     1178      +11     
Flag Coverage Δ
unittests 46.23% <56.32%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[BUG] UpdateNodeStatus silently swallows errors and returns stale node on failure

1 participant