Skip to content

Commit 5df80b3

Browse files
sylrclaude
andcommitted
fix(api): prevent panic on 204 No Content responses with Go 1.26
Go 1.26 enforces that response status codes like 204 No Content must not have a body. The OTLP middleware's finalize() method was calling Write() even with empty data, causing a panic. Additionally, NoContent() was routing through writeJSON() which unnecessarily set Content-Type header on bodyless responses. Constraint: Go 1.26 strictly enforces RFC 7230 no-body status codes Rejected: Recover from panic in finalize | masks the root cause Confidence: high Scope-risk: narrow Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2844b0a commit 5df80b3

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

pkg/transport/api/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NotFound(w http.ResponseWriter, err error) {
4141
}
4242

4343
func NoContent(w http.ResponseWriter) {
44-
writeJSON(w, http.StatusNoContent, nil)
44+
w.WriteHeader(http.StatusNoContent)
4545
}
4646

4747
func Forbidden(w http.ResponseWriter, code string, err error) {

pkg/transport/httpserver/otlp_middleware.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ func (w *responseWriter) finalize() {
2626
if w.Header().Get("Content-Type") == "application/octet-stream" {
2727
return
2828
}
29+
if len(w.data) == 0 {
30+
return
31+
}
2932
_, err := w.ResponseWriter.Write(w.data)
3033
if err != nil {
3134
panic(err)

0 commit comments

Comments
 (0)