From 5ce287f6e95b591d7bf8cd3875323465e99e0c13 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 28 Sep 2026 10:56:45 +0200 Subject: [PATCH] fix(storage): bound the upload part size so uploads don't OOM the registry Uploads are streamed to S3 with an unknown size. minio-go then sizes one part for the largest possible object (528 MiB) and allocates it up front, which killed the registry at its 384 MiB limit on every upload (staging, S3 test of the acceptance run). A fixed 16 MiB part caps the buffer. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB --- internal/storage/storage.go | 13 ++++++++++++- internal/storage/storage_test.go | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/internal/storage/storage.go b/internal/storage/storage.go index 9ae88c9..d20e322 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -78,8 +78,19 @@ func NewS3(ctx context.Context, cfg Config) (*S3, error) { return &S3{client: client, bucket: cfg.Bucket}, nil } +// uploadPartSize is the multipart chunk minio-go buffers in memory. Uploads +// are streamed with an unknown size, and minio-go then sizes a part for the +// largest possible object (5 TiB / 10000 parts, about 550 MiB) and allocates +// it up front: every upload killed the registry at its 384 MiB limit. 16 MiB +// parts cap the buffer and still allow objects far beyond the upload limit. +const uploadPartSize = 16 << 20 + +func putOptions(contentType string) minio.PutObjectOptions { + return minio.PutObjectOptions{ContentType: contentType, PartSize: uploadPartSize} +} + func (s *S3) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error { - _, err := s.client.PutObject(ctx, s.bucket, key, r, size, minio.PutObjectOptions{ContentType: contentType}) + _, err := s.client.PutObject(ctx, s.bucket, key, r, size, putOptions(contentType)) return err } diff --git a/internal/storage/storage_test.go b/internal/storage/storage_test.go index 08d0f85..cca3b30 100644 --- a/internal/storage/storage_test.go +++ b/internal/storage/storage_test.go @@ -55,3 +55,18 @@ func TestMemory(t *testing.T) { t.Fatal("FailPut ignored") } } + +// A streamed upload (size -1) must not make minio-go allocate a part sized +// for a 5 TiB object. +func TestPutOptions_boundPartSize(t *testing.T) { + o := putOptions("application/pdf") + if o.ContentType != "application/pdf" { + t.Fatalf("content type = %q", o.ContentType) + } + if o.PartSize != 16<<20 { + t.Fatalf("part size = %d, want 16 MiB", o.PartSize) + } + if o.ConcurrentStreamParts { + t.Fatal("concurrent stream parts would buffer several parts at once") + } +}