storage 9.0.0: non-resumable uploads read the whole body into memory before sending

オープン
#9,872 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
56/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, typescript

調査の方向性

Start with File#startSimpleUpload_ and the reqOpts.multipart branch in build/cjs/src/storage-transport.js, then compare the multipart request path with version 8.4.0. Reproduce with the supplied fake-gcs-server script and check both memory use on a large non-resumable upload and the payload containing the boundary string. Done when stream uploads stay bounded in memory and that payload is stored intact.

索引モデルが issue の本文から書いたものです。

説明

Package: @google-cloud/storage (handwritten/storage)

Environment

  • @google-cloud/storage 9.0.0 (gaxios 8.3.3, google-auth-library 11.3.4)
  • Node 22.23.4 (same under Bun 1.4.4)
  • 8.4.0 streams the same upload

Steps to reproduce

Against fake-gcs-server (docker run -p 4443:4443 fsouza/fake-gcs-server -scheme http -backend memory), so no bucket or credentials are needed:

import { Readable } from "node:stream";
import { pipeline } from "node:stream/promises";
import { Storage } from "@google-cloud/storage";
import { PassThroughClient } from "google-auth-library";

const apiEndpoint = "http://127.0.0.1:4443";
await fetch(`${apiEndpoint}/storage/v1/b?project=p`, {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ name: "repro-bucket" }),
});
// PassThroughClient only because of a separate 9.0.0 change: a custom apiEndpoint now asks for credentials.
const storage = new Storage({ projectId: "p", apiEndpoint, authClient: new PassThroughClient() });

const MiB = 256;
let sent = 0;
const source = new Readable({
  read() {
    this.push(sent < MiB ? Buffer.alloc(1024 * 1024, sent++ & 255) : null);
  },
});
let peak = 0;
const timer = setInterval(() => (peak = Math.max(peak, process.memoryUsage().rss)), 10);
await pipeline(
  source,
  storage.bucket("repro-bucket").file("big.bin").createWriteStream({ resumable: false }),
);
clearInterval(timer);
console.log({ peakRssMiB: Math.round(peak / 2 ** 20) });

Actual (9.0.0)

Peak RSS grows with the size of the upload:

upload 8.4.0 9.0.0
32 MiB 114 MiB 169 MiB
256 MiB 128 MiB 842 MiB

Under Bun 1.4.4, the 256 MiB upload peaks at 74 MiB on 8.4.0 and 1,065 MiB on 9.0.0. file.save(data, { resumable: false }) takes the same path. Resumable uploads still stream (about 45 MiB for 256 MiB).

Expected (8.4.0)

The media part is streamed, so memory stays flat whatever the size of the upload.

Cause

File#startSimpleUpload_ passes the write stream as the second multipart part (content: writeStream), and StorageTransport.makeRequest (build/cjs/src/storage-transport.js, the reqOpts.multipart branch) collects every chunk of a stream part into an array and Buffer.concat()s it before the request goes out. 8.x streamed the parts through teeny-request's multipart stream.

A second problem in the same code

The multipart boundary is now the fixed string ===============storage_multipart_boundary== (8.x used a random UUID per request), so content that contains that line breaks the framing. Saving this 62-byte buffer with resumable: false:

Buffer.from("before\r\n--===============storage_multipart_boundary==\r\nafter\r\n")

8.4.0 stores it intact. On 9.0.0, fake-gcs-server rejects the upload with 500 malformed MIME header: missing colon: "after".

Suggested fix

Stream a stream part into the request body instead of buffering it, and generate a random boundary for each request.

主要言語
TypeScript
スター
3.2k
フォーク
732
平均マージ
2日 11時間
マージ済み PR(30日)
99

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

googleapis/google-cloud-node のほかの issue

googleapis/google-cloud-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。