gaxios + googleapis-common: a request body stream that errors crashes the process (unhandled 'error' event)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 66/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, typescript
調査の方向性
Start in core/packages/gaxios by tracing how stream data is accepted before dispatch, then inspect core/packages/nodejs-googleapis-common/apirequest.ts and multipartUpload() for the pipe chain. Reproduce both cases with fs.createReadStream() on a nonexistent path; done means the request rejects with the stream error and the process remains alive.
索引モデルが issue の本文から書いたものです。
説明
Affects core/packages/gaxios (7.3.1) and core/packages/nodejs-googleapis-common (9.1.0), Node 22.14. Filed here since both packages moved into this monorepo (the standalone gaxios repo is archived).
A Node Readable passed as a request body that emits 'error' before it is consumed fires the event with no listener attached, and Node terminates the process. The everyday trigger is fs.createReadStream(path) on an unopenable path (ENOENT/EACCES): it returns synchronously and reports the failure as an async event. In a long-lived server, one bad path kills every concurrent request — we hit this in production via a Drive media upload.
There are two independent unhandled windows:
A. gaxios: stream data before dispatch
import { request } from 'gaxios';
import fs from 'node:fs';
try {
await request({ url: 'https://example.com/', method: 'POST', data: fs.createReadStream('/nonexistent/file.bin') });
} catch (e) {
console.log('rejected cleanly:', e.code); // never reached
}
// process exits 1: Unhandled 'error' event ... ENOENT
Expected: the promise rejects with the ENOENT. Observed: process crash. Notably node-fetch handles the same stream correctly when called directly (fetch(url, { method: 'POST', body: fs.createReadStream('/nonexistent') }) rejects cleanly and the process survives), so the missing listener is in gaxios's own window before the fetch backend takes ownership.
B. googleapis-common: the multipart upload pipe chain
apirequest.ts multipartUpload() wires the caller's media body as:
part.body.pipe(pStream).pipe(rStream);
.pipe() does not propagate 'error' events, so (1) an error on part.body is unhandled → process crash, and (2) even if it were handled, rStream (what the request actually sends) never learns about it, so the request could not fail cleanly either. Mechanism in isolation:
import fs from 'node:fs';
import { PassThrough } from 'node:stream';
const src = fs.createReadStream('/nonexistent/file.bin');
const p = new PassThrough(), r = new PassThrough();
src.pipe(p).pipe(r); r.resume();
// process exits 1: Unhandled 'error' event ... ENOENT
This is the path any googleapis/@googleapis/* media upload takes (e.g. drive.files.create with media.body a file stream), which is how it surfaced for us.
Suggested fix
- gaxios: attach an
'error'listener when accepting a streamdataand reject the in-flight request promise with the error. - googleapis-common: in
multipartUpload(), forward errors down the chain, e.g.part.body.on('error', err => rStream.destroy(err))(and the same forpStream), so the request rejects instead of the process dying.
Workaround for users
Open the fd first so the open-failure class throws inside try/catch, and keep a listener for late errors:
const handle = await fs.promises.open(path, 'r');
const stream = handle.createReadStream();
stream.on('error', () => {});
- 主要言語
- 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 日以内に返信