Channel response appends JSON null after context timeout
評価
調査の方向性
バグは responder.go にあります。コンテキストがキャンセルされると channelIntoSlice が http.Error で 504 を書き込んで nil を返しますが、その後も DefaultResponder は JSON(w, r, nil) を呼び出しています。issue のスニペットで再現し、そのあと DefaultResponder のチャネル分岐を確認して、タイムアウト後にどこで停止すべきかを調べてください。body が正確に Server Timeout\n になり、既存の responder テストがすべて通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
When DefaultResponder receives a channel value and the request context is canceled while it waits, it writes a 504 timeout response and appends JSON null to the body. The result is a mixed text/JSON response rather than the timeout body alone.
Reproduced on latest release v1.0.3 and current main commit 14f1cb3d5c2969d6e462632a205eacb6421eb4dc with Go 1.27.1:
package main
import (
"context"
"fmt"
"net/http/httptest"
"github.com/go-chi/render"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
cancel()
request := httptest.NewRequest("GET", "/", nil).WithContext(ctx)
request.Header.Set("Accept", "application/json")
response := httptest.NewRecorder()
channel := make(chan string) // open, with no available value
render.DefaultResponder(response, request, channel)
fmt.Printf("status=%d content-type=%q body=%q\n",
response.Result().StatusCode,
response.Result().Header.Get("Content-Type"),
response.Body.String())
}
Observed:
status=504 content-type="text/plain; charset=utf-8" body="Server Timeout\nnull\n"
Expected: after sending the timeout response, no second payload should be written. The body should be "Server Timeout\n".
In responder.go, channelIntoSlice calls http.Error(..., 504) and returns nil on cancellation. DefaultResponder then continues to JSON(w, r, nil), which writes the extra null.
- 主要言語
- Go
- スター
- 340
- フォーク
- 69
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
go-chi/render のほかの issue
-
Render and Bind panic on unexported nested interface fields対応中かも @duongynhi000005-oss が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
-
Any concern render.JSON() can leak internal errors to outside?対応中かも @team-humaki が 50 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
-
render.Render() writes to writer unexpected data of aliased type対応中かも @team-humaki が 49 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
似ている issue
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
WriterSetTimes: the UTIME_NOW check fails when the kernel uses its coarse clock対応中かも @JakeChampion が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
JakeChampion/lang#14224 ·
メンテナーはふだん 1 日以内に返信
-
agent-butler-finding bug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
jordansmall/spindrift#6391 ·
メンテナーはふだん 1 日以内に返信
-
common.Retry: data race on the shared response/err variables when the request context ends mid-attempt (v65.127.0, v65.128.0)対応中かも @kmohit00 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
oracle/oci-go-sdk#676 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
SAP/crossplane-provider-btp#1175 ·
メンテナーはふだん 1 日以内に返信