Dispatcher panics when a failed delivery returns a response body larger than 768 bytes

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

メンテナーはふだん 1 日以内に返信

@RaphaelFakhri がすでに取り組んでいます。

2026年11月3日 から。

  • #9505 @RaphaelFakhri による — オープン
  • #9507 @amarkdotdev による — オープン

評価

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

調査の方向性

パニックは pkg/kncloudevents/event_dispatcher.go の593行目付近にある dispatchExecutionInfoTransformers から発生しています。このバッファは KnativeErrorDataExtensionMaxLength で上限が設定されていますが、レスポンスボディ全体がそこにエンコードされています。まずこの関数と、TestSendEvent の invalid destination with a large response body and delivery option のケースを読み、そのテストを実行して index-out-of-range パニックを再現してください。768バイトを超えるボディでテストが通り、knativeerrordata の値がボディを1024文字に切り詰めたものの base64 になっていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug
When a subscriber or trigger destination returns a non-2xx response with a body longer than 768 bytes, and the delivery has a dead letter sink (or a reply), the dispatcher panics with runtime error: index out of range in encoding/base64.(*Encoding).Encode.

dispatchExecutionInfoTransformers in pkg/kncloudevents/event_dispatcher.go caps the destination buffer at KnativeErrorDataExtensionMaxLength (1024) but encodes the whole response body into it:

encodedLen := base64.StdEncoding.EncodedLen(bodyLen)
if encodedLen > attributes.KnativeErrorDataExtensionMaxLength {
	encodedLen = attributes.KnativeErrorDataExtensionMaxLength
}
encodedBuf := make([]byte, encodedLen)
base64.StdEncoding.Encode(encodedBuf, httpResponseBody)

base64.Encode always writes EncodedLen(len(src)) bytes, so it panics if the buffer is shorter than that.

Effects:

  • In the in-memory channel dispatcher, the fanout runs each subscription in its own goroutine, so the panic is not recovered and the dispatcher process exits.
  • In the broker filter, net/http recovers the panic, the connection is dropped, and the event never reaches the dead letter sink.

Expected behavior
The event goes to the dead letter sink, and knativeerrordata holds the base64-encoded response body truncated to 1024 characters.

To Reproduce

  1. Create a Trigger or Subscription with delivery.deadLetterSink set.
  2. Point the subscriber at a service that returns HTTP 500 with a body of 2000 bytes (for example, an HTML error page).
  3. Send an event. The dispatcher logs panic: runtime error: index out of range and the dead letter sink receives nothing.

The unit test case invalid destination with a large response body and delivery option in TestSendEvent reproduces this on main:

panic: runtime error: index out of range [3] with length 0
encoding/base64.(*Encoding).Encode(...)
knative.dev/eventing/pkg/kncloudevents.dispatchExecutionInfoTransformers(...)
	pkg/kncloudevents/event_dispatcher.go:593

Knative release version
main (2153953). The same code has been in place since at least the kncloudevents refactor (#7092).

Additional context
Bodies of 768 bytes or fewer are not affected, because their encoded length fits in the buffer.

主要言語
Go
スター
1.6k
フォーク
637
平均マージ
10時間 57分
マージ済み PR(30日)
13

環境構築

はじめの一歩

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

knative/eventing のほかの issue

knative/eventing の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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