Channel response appends JSON null after context timeout

オープン 初心者向け
#71 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@awais-ur-rehman がすでに取り組んでいます。

2026年11月4日 から。

  • #73 @awais-ur-rehman による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
api

調査の方向性

バグは 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

go-chi/render のほかの issue

go-chi/render の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。