storage: `file.download()` of a large object emits MaxListenersExceededWarning since 8.0 (response body piped twice)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 半日
- 初心者へのやさしさ
- 52/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- google-cloud, node.js, typescript
- 領域
- cloud
調査の方向性
Start with the repro script in the issue, which needs no credentials and triggers the warning on the 2 MiB object. The two pipelines that both read the response body are in build/cjs/src/file.js (createReadStream's onResponse) and in teeny-request's build/src/index.js (stream mode, plus the .resume() call in makeRequest). Done means the 5-download loop reports 0 MaxListenersExceededWarning while the downloads still return the correct bytes, and the fix may belong in either package.
索引モデルが issue の本文から書いたものです。
説明
Environment
@google-cloud/storage8.4.0 (also 8.2.0); not 7.16.0teeny-request11.1.1,node-fetch3.3.2- Node.js 22.23.2
What happens
Each file.download() / createReadStream() of an object large enough to still be streaming when the response arrives prints:
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PassThrough]. MaxListeners is 10.
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [PassThrough]. MaxListeners is 10.
The listeners are released when the download ends, so nothing actually leaks. But the warning fires once per download, so it floods the logs.
Cause
The PassThrough is node-fetch's response body. Two pipelines read it:
createReadStream'sonResponserunspipeline(rawResponseStream, ...transformStreams, throughStream, onComplete)(build/cjs/src/file.js, 8.4.0).- teeny-request's stream mode runs
pipeline(responseStream, requestStream, () => {})on the same body (teeny-request/build/src/index.js,requestStream.once('response', ...)). ThenmakeRequestcalls.resume()on that request stream and discards what it reads.
Together with node-fetch's own pump(response_, new PassThrough()) and the error listeners from node-fetch's Body and teeny-request, that comes to 11. With node-fetch 2 (storage 7.x) the total stays under 10, which is presumably why 7.x is quiet. Small objects finish before the second pipeline attaches, so they never warn.
Repro (no credentials, local server)
const http = require('node:http');
const crypto = require('node:crypto');
const { Storage, CRC32C } = require('@google-cloud/storage');
const body = Buffer.alloc(2 * 1024 * 1024, 'x'); // 2 MiB; a few KiB does not trigger it
const md5 = crypto.createHash('md5').update(body).digest('base64');
const c = new CRC32C(); c.update(body); const crc32c = c.toString();
let warnings = 0;
process.on('warning', (w) => { if (w.name === 'MaxListenersExceededWarning') warnings++; });
const server = http.createServer((req, res) => {
res.writeHead(200, {
'content-type': 'application/octet-stream',
'content-length': body.length,
'x-goog-hash': `crc32c=${crc32c},md5=${md5}`,
'x-goog-stored-content-encoding': 'identity',
});
res.end(body);
});
server.listen(0, '127.0.0.1', async () => {
const storage = new Storage({ apiEndpoint: `http://127.0.0.1:${server.address().port}`, projectId: 'test' });
const file = storage.bucket('bucket').file('object');
for (let i = 0; i < 5; i++) await file.download();
console.log(`5 downloads, ${warnings} MaxListenersExceededWarning`);
server.close();
});
Output: 8.4.0 → 5 downloads, 10 MaxListenersExceededWarning; 8.2.0 → 10; 7.16.0 → 0.
Expected
The response body is consumed once, either by storage's pipeline or by the request stream it gets from teeny-request, not by both. Then no warning.
- 主要言語
- TypeScript
- スター
- 3.2k
- フォーク
- 732
- 平均マージ
- 2日 11時間
- マージ済み PR(30日)
- 99
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
googleapis/google-cloud-node のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
googleapis/google-cloud-node#9854 ·
メンテナーはふだん 1 日以内に返信
-
pubsub: "Operation attempted on ended Span" when a modack is flushed after the message was ackedオープンapi: pubsub
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
googleapis/google-cloud-node#9853 ·
メンテナーはふだん 1 日以内に返信
-
storage: V4 getSignedUrl sorts canonical headers with localeCompare, so they disagree with X-Goog-SignedHeaders対応中かも @itsrayeedscodespace が 9 日前に担当しました。 オープンapi: storage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
googleapis/google-cloud-node#9840 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
firestore: getPartitions() emits gax AutopaginateTrueWarning in every process対応中かも @TheRealDanii が 13 日前に担当しました。 オープンapi: firestore
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
googleapis/google-cloud-node#9736 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
googleapis/google-cloud-node#9723 ·
メンテナーはふだん 1 日以内に返信
googleapis/google-cloud-node の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
ilan-pinto/roaring-lions#1552 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug: [React Native/Android] KeepAliveService never starts when CAMERA is not granted (Android 14+)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudflare/realtimekit-ui#208 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
usebruno/bruno-vscode#235 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信