OCI pusher panics when reused for a second upload

Aperta
#4,131 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@shreyashsri79 ci sta già lavorando.

Dal 5/11/2026.

  • #4132 di @shreyashsri79 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

The issue identifies pkg/oci/pusher.go:212 and provides a reproducible regression test for pkg/oci/pusher_progress_test.go. Run the supplied go test -race -count=1 -timeout=45s -run '^TestPusher_Reuse$' ./pkg/oci command to see the failure. The issue says a focused fix and reuse/retry coverage are already being worked on, and links open pull request #4132.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Reusing one OCI Pusher for two uploads panics on the second upload. This affects callers that retain the pusher, including a functions.Client configured with WithPusher.

Reproduced on main at 56e770ff38205a4dd33c1595cac28e9f8d0e3e3b, Linux amd64, Go 1.27.3.

NewPusher allocates updates once. The pinned go-containerregistry closes that channel when remote.WriteIndex finishes, so the next upload receives the closed channel again.

Reproduce: add the test below as pkg/oci/pusher_progress_test.go, then run:

go test -race -count=1 -timeout=45s -run '^TestPusher_Reuse$' ./pkg/oci

Expected: both calls return the image-index digest. Actual: first push succeeds; second panics with close of closed channel in remote.(*progress).Close, called through pkg/oci/pusher.go:212. The regression failed locally (exit 1, package runtime 0.074s). It uses an empty OCI layout and an in-process test registry; no function build, external registry or Kubernetes cluster is needed.

Regression test
package oci

import (
	"io"
	"log"
	"net/http/httptest"
	"path/filepath"
	"strings"
	"testing"

	"github.com/google/go-containerregistry/pkg/registry"
	"github.com/google/go-containerregistry/pkg/v1/empty"
	"github.com/google/go-containerregistry/pkg/v1/layout"

	fn "knative.dev/func/pkg/functions"
)

// A client can reuse its pusher when a function is built and pushed again.
func TestPusher_Reuse(t *testing.T) {
	server := httptest.NewServer(registry.New(registry.Logger(log.New(io.Discard, "", 0))))
	t.Cleanup(server.Close)

	f := fn.Function{Root: t.TempDir()}
	f.Build.Image = strings.TrimPrefix(server.URL, "http://") + "/funcs/reuse:latest"
	if _, err := layout.Write(filepath.Join(f.Root, fn.RunDataDir, fn.BuildDir, "oci"), empty.Index); err != nil {
		t.Fatal(err)
	}
	want, err := empty.Index.Digest()
	if err != nil {
		t.Fatal(err)
	}

	pusher := NewPusher(true, true, false)
	for i := 0; i < 2; i++ {
		got, err := pusher.Push(t.Context(), f)
		if err != nil {
			t.Fatalf("push %d: %v", i+1, err)
		}
		if got != want.String() {
			t.Fatalf("push %d: digest = %q, want %q", i+1, got, want)
		}
	}
}

I am working on a focused fix that gives each upload its own progress channel and drains it until the producer finishes, with reuse/retry coverage. No API, authentication, dependency or CI changes are proposed.

Prepared with Codex assistance. Tests reported above were actually run against unchanged production code. Full make test, make check and hosted CI have not run yet.

Lingua principale
Go
Stelle
366
Fork
231
Merge medio
2g 23h
PR unite (30g)
50

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di knative/func

Tutte le issue di knative/func

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.