fix: add missing return after WriteErr in GetPods handler to prevent superfluous response write - #2772
Conversation
…superfluous response write
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
Hi maintainers @zyjhtangtang @luc99hen sir
Everything builds cleanly and all tests pass. Would love a quick review when you get a chance! Thanks! |



What type of PR is this?
/kind bug
What this PR does / why we need it:
In
pkg/yurthub/otaupdate/ota.go, theGetPodsHTTP handler callsutil.EncodePods(podList)and, on failure, correctly callsutil.WriteErr(w, "Encode pod list failed", http.StatusInternalServerError)to write a 500 response — but was missing a
returnstatementimmediately after.
Without the
return, execution falls through toutil.WriteJSONResponse(w, data)withdata == nil, which attempts tocall
w.WriteHeader(http.StatusOK)(200) on a response that has alreadybeen committed with a 500 status. This produces a Go HTTP warning
(
http: superfluous response.WriteHeader call) and appendsnullto theresponse 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 byreturn— this singlebranch was the only one missing it.
This PR adds the missing
returnstatement and addsTestGetPods_EncodePodsErrorto verify that on an encoding failure onlythe 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/...— cleango vet ./pkg/yurthub/otaupdate/...— cleango test -v ./pkg/yurthub/otaupdate/...— all tests pass, including the newTestGetPods_EncodePodsErrorDoes this PR introduce a user-facing change?
other Note