OCI pusher panics when reused for a second upload

未关闭
#4,131 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@shreyashsri79 已经在做这个了。

开始于 2026年11月5日。

  • #4132 来自 @shreyashsri79 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
go
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Go
星标
366
派生
231
平均合并
2 天 23 小时
30 天内合并 PR
50

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

knative/func 的其他 Issue

查看 knative/func 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。