gaxios + googleapis-common: a request body stream that errors crashes the process (unhandled 'error' event)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 66/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- node.js, typescript
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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', () => {});
- Langage dominant
- TypeScript
- Étoiles
- 3.2k
- Forks
- 732
- Merge moyen
- 2 j 11 h
- PR mergées (30 j)
- 99
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de googleapis/google-cloud-node
-
Broken deprecation chainOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
googleapis/google-cloud-node#9854 ·
Les mainteneurs répondent en général sous 1 jour
-
pubsub: "Operation attempted on ended Span" when a modack is flushed after the message was ackedOuverteapi: pubsub
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
googleapis/google-cloud-node#9853 ·
Les mainteneurs répondent en général sous 1 jour
-
storage: V4 getSignedUrl sorts canonical headers with localeCompare, so they disagree with X-Goog-SignedHeadersPeut-être pris @itsrayeedscodespace l’a pris il y a 9 jours. Ouverteapi: storage
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
googleapis/google-cloud-node#9840 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
firestore: getPartitions() emits gax AutopaginateTrueWarning in every processPeut-être pris @TheRealDanii l’a pris il y a 13 jours. Ouverteapi: firestore
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
googleapis/google-cloud-node#9736 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
googleapis/google-cloud-node#9723 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de googleapis/google-cloud-node
Issues similaires
-
area: batch
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
inabagumi/shinju-date#7294 ·
Les mainteneurs répondent en général sous 1 jour
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
streaming-video-technology-alliance/common-media-library#700 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
vercel-labs/ui#809 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
KrisCris/village-in-the-shade-guide#75 ·
Les mainteneurs répondent en général sous 1 jour
-
bot:ai-assisted component:platform-js status:untriaged
Difficulté 1/5 Moins d'une heure Accessibilité débutants 74/100
midnightntwrk/platform-js#38 ·