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

Abierto Apto para principiantes
#9,504 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@RaphaelFakhri ya está trabajando en esto.

Desde el 3/11/2026.

  • #9505 de @RaphaelFakhri — abierto
  • #9507 de @amarkdotdev — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
74/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
backend

Línea de trabajo

El panic viene de dispatchExecutionInfoTransformers en pkg/kncloudevents/event_dispatcher.go, alrededor de la línea 593, donde el búfer se limita a KnativeErrorDataExtensionMaxLength pero se codifica en él el cuerpo completo de la respuesta. Empieza leyendo esa función y el caso TestSendEvent invalid destination with a large response body and delivery option, y luego ejecútalo para reproducir el panic de índice fuera de rango. Está terminado cuando la prueba pasa con un cuerpo de más de 768 bytes y el valor knativeerrordata es el base64 del cuerpo truncado a 1024 caracteres.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
1.6k
Forks
637
Merge medio
10 h 57 min
PR fusionados (30 d)
13

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de knative/eventing

Todos los issues de knative/eventing

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.