fix(storage): bound the upload part size so uploads don't OOM the registry (#44)
ci / shared (push) Successful in 13s
ci / test (push) Successful in 23m21s
ci / image (push) Successful in 35s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit was merged in pull request #44.
This commit is contained in:
sharangandClaude Opus 5.5 committed 2026-09-28 09:21:07 +00:00
1 parent 485f3432ac
commit b424e001dc
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")
}
}