Skip to content

fix: add missing return after WriteErr in GetPods handler to prevent superfluous response write - #2772

Open
WorrierKhushal wants to merge 9 commits into
openyurtio:masterfrom
WorrierKhushal:fix/2771-otaupdate-getpods-missing-return
Open

fix: add missing return after WriteErr in GetPods handler to prevent superfluous response write#2772
WorrierKhushal wants to merge 9 commits into
openyurtio:masterfrom
WorrierKhushal:fix/2771-otaupdate-getpods-missing-return

Conversation

@WorrierKhushal

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

In pkg/yurthub/otaupdate/ota.go, the GetPods HTTP handler calls
util.EncodePods(podList) and, on failure, correctly calls
util.WriteErr(w, "Encode pod list failed", http.StatusInternalServerError)
to write a 500 response — but was missing a return statement
immediately after.

Without the return, execution falls through to
util.WriteJSONResponse(w, data) with data == nil, which attempts to
call w.WriteHeader(http.StatusOK) (200) on a response that has already
been committed with a 500 status. This produces a Go HTTP warning
(http: superfluous response.WriteHeader call) and appends null to the
response body after the 500 error payload, corrupting the HTTP response
for any client hitting this error path.

Every other error branch in this same file (lines 70, 76, 85, 110, 115,
123, 131, 136, 145, 153) already follows the convention of
util.WriteErr(...) immediately followed by return — this single
branch was the only one missing it.

This PR adds the missing return statement and adds
TestGetPods_EncodePodsError to verify that on an encoding failure only
the 500 status is written and the handler returns cleanly.

Which issue(s) this PR fixes:

Fixes #2771

Special notes for your reviewer:

  • go build ./pkg/yurthub/otaupdate/... — clean
  • go vet ./pkg/yurthub/otaupdate/... — clean
  • go test -v ./pkg/yurthub/otaupdate/... — all tests pass, including the new TestGetPods_EncodePodsError
  • One-line change, zero risk of behavioral regression on the success path
  • No exported function signatures changed

Does this PR introduce a user-facing change?

NONE

other Note

@WorrierKhushal
WorrierKhushal requested a review from a team as a code owner August 27, 2026 14:20
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.81818% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.24%. Comparing base (ddf22f7) to head (52ac954).
⚠️ 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    #2772      +/-   ##
==========================================
+ Coverage   46.20%   46.24%   +0.04%     
==========================================
  Files         405      405              
  Lines       27540    27633      +93     
==========================================
+ Hits        12724    12779      +55     
- Misses      13649    13676      +27     
- Partials     1167     1178      +11     
Flag Coverage Δ
unittests 46.24% <56.81%> (+0.04%) ⬆️

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.

@sonarqubecloud

Copy link
Copy Markdown

@WorrierKhushal

Copy link
Copy Markdown
Contributor Author

Hi maintainers @zyjhtangtang @luc99hen sir
i just wanted to tell about my this pr :

  • The Bug: In pkg/yurthub/otaupdate/ota.go, the GetPods handler was missing a return statement right after util.WriteErr(...) when EncodePods failed. This caused a fall-through to WriteJSONResponse, resulting in a Go HTTP warning (superfluous response.WriteHeader call) and response corruption.

  • The Fix: Added the missing return statement (consistent with every other error branch in this file) and added a new unit test TestGetPods_EncodePodsError to prevent regressions.

Everything builds cleanly and all tests pass. Would love a quick review when you get a chance! Thanks!

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] Missing return statement after error response in otaupdate GetPods handler causes corrupted HTTP response

1 participant