Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

CompressionFilter’s IdentityHandler.writeMessage calls Buffer-only .copy() on caller-provided message

Aperta Adatta ai principianti
#3,050 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
node.js, typescript
Ambito
api, backend

Direzione di ricerca

Inizia in packages/grpc-js/src/compression-filter.ts, in IdentityHandler.writeMessage, quindi riproduci il fallimento con un requestSerialize personalizzato che restituisce un Uint8Array. Verifica che lo stesso percorso accetti messaggi sia Uint8Array sia Buffer senza il TypeError e produca un risultato o uno stato RPC significativo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem description

CompressionFilter's IdentityHandler.writeMessage (packages/grpc-js/src/compression-filter.ts) calls message.copy(output, 5), which is a Buffer-only method:

async writeMessage(message, compress) {
    const output = Buffer.allocUnsafe(message.length + 5);
    output.writeUInt8(0, 0);
    output.writeUInt32BE(message.length, 1);
    message.copy(output, 5);   // ← Buffer-only
    return output;
}

Uint8Array.prototype.copy is undefined. If the caller-provided request serializer produces a Uint8Array rather than a Buffer, this throws TypeError: message.copy is not a function. The thrown error then propagates as a code: undefined, details: undefined, empty-Metadata gRPC status (the empty-status side is tracked separately: https://github.com/grpc/grpc-node/issues/3051).

Uint8Array request serializers are reachable in practice via protobufjs, which falls back to Uint8Array-returning Writer.alloc whenever protobufjs.util.Buffer is unset. One concrete trigger is the @protobufjs/[email protected] regression — see protobufjs/protobuf.js#2214 — where bundlers (Turbopack, certain webpack configurations) statically rewrite the new dynamic require(name) to throw MODULE_NOT_FOUND, leaving util.Buffer = null in any bundled server build.

Reproduction steps

In a Next.js 16 application with output: "standalone" (Turbopack):

  1. Add @google-cloud/[email protected] and use it from a Server Component (any call works: collection(...).get(), doc(...).get(), etc.).
  2. Ensure @protobufjs/inquire resolves to 1.1.1 (the default with [email protected]+).
  3. next build and run the standalone output. Trigger any Firestore call.

Expected: the call succeeds or fails with a meaningful status.
Actual: the call's callback receives Error: undefined undefined: undefined with { code: undefined, details: undefined, metadata: Metadata { internalRepr: Map(0) {}, options: {} } }. Running with GRPC_TRACE=all GRPC_VERBOSITY=DEBUG shows cancelWithStatus code: undefined details: "undefined" firing within 1 ms of write() called with message of length N.

Independent of protobufjs, the same path is reachable by registering a custom method whose requestSerialize returns new Uint8Array([...]) and calling client.makeUnaryRequest(...).

Environment
Additional context

Suggested fix: output.set(message, 5) in place of message.copy(output, 5). Buffer extends Uint8Array and both expose .set, so the call works for either input.

Impact in our deployment: a Dependabot bump to [email protected] (which pulls @protobufjs/[email protected] transitively) caused this TypeError on every Firestore call. Under google-gax retry the undefined code is treated as retryable, so the call retries for the gax budget before bubbling up. For server-streaming RPCs under additional SDK-level retry (Firestore's QueryUtil._stream), every request hangs for ~45 s and then 500s. We hit a production outage before identifying the underlying chain.

Lingua principale
TypeScript
Stelle
4.8k
Fork
716
Merge medio
1g 18h
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di grpc/grpc-node

Tutte le issue di grpc/grpc-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.