fix(storage): bound the upload part size so uploads don't OOM the registry
ci / shared (pull_request) Successful in 14s
ci / test (pull_request) Successful in 23m40s
ci / image (pull_request) Skipped

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-09-28 10:56:45 +02:00
1 parent 485f3432ac
commit 5ce287f6e9
2 files changed
+27 -1

No files matched your search

+12 -1
View File
@@ -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
}
+15
View File
@@ -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")
}
}