Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility error with Node 22.7 #8455

Closed
lucasmengarda opened this issue Aug 23, 2024 · 9 comments
Closed

Compatibility error with Node 22.7 #8455

lucasmengarda opened this issue Aug 23, 2024 · 9 comments

Comments

@lucasmengarda
Copy link

Operating System

Linux

Environment (if applicable)

Node 22.7

Firebase SDK Version

9.23.0

Firebase SDK Product(s)

Firestore

Project Tooling

React app with Firebase

Detailed Problem Description

When running a Node.js application that interacts with Firestore on the Google Cloud Platform (GCP), specifically in a Cloud Run environment, I encounter a RangeError [ERR_BUFFER_OUT_OF_BOUNDS]. This error occurs when attempting to retrieve a document from Firestore using the following code:

This issue began happening after updating to Node.js 22.7. I have since downgraded to a previous version, which resolved the issue, but I wanted to report this problem.

Steps and code to reproduce issue

const docRef = database.collection('users').doc(uid);
const doc = await docRef.get();

@lucasmengarda lucasmengarda added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Aug 23, 2024
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@aalej aalej added api: firestore needs-attention and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Aug 23, 2024
@dlarocque
Copy link
Contributor

Looking at the Node 22.7 release notes, I see quite a few changes have been made to Buffer in #54311, #54324, and #54087. This might be a Node bug introduced by these changes.

@dlarocque
Copy link
Contributor

Here's a full stack trace:

[2024-08-23T18:57:08.150Z]  @firebase/firestore: Firestore (10.13.0): INTERNAL UNHANDLED ERROR:  RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: "length" is outside of buffer bounds
    at proto.utf8Write (node:internal/buffer:1066:13)
    at Op.writeStringBuffer [as fn] (/Users/dlarocque/workspace/repro/nodebug/node_modules/protobufjs/src/writer_buffer.js:61:13)
    at BufferWriter.finish (/Users/dlarocque/workspace/repro/nodebug/node_modules/protobufjs/src/writer.js:453:14)
    at /Users/dlarocque/workspace/repro/nodebug/node_modules/@grpc/proto-loader/build/src/index.js:177:109
    at Array.map (<anonymous>)
    at createPackageDefinition (/Users/dlarocque/workspace/repro/nodebug/node_modules/@grpc/proto-loader/build/src/index.js:177:39)
    at Module.fromJSON (/Users/dlarocque/workspace/repro/nodebug/node_modules/@grpc/proto-loader/build/src/index.js:230:12)
    at loadProtos (file:///Users/dlarocque/workspace/repro/nodebug/node_modules/@firebase/firestore/dist/index.node.mjs:22129:43)
    at newConnection (file:///Users/dlarocque/workspace/repro/nodebug/node_modules/@firebase/firestore/dist/index.node.mjs:22151:20)
    at OnlineComponentProvider.createDatastore (file:///Users/dlarocque/workspace/repro/nodebug/node_modules/@firebase/firestore/dist/index.node.mjs:26266:28)
node:internal/process/promises:394
    triggerUncaughtException(err, true /* fromPromise */);
    ^

RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: "length" is outside of buffer bounds
    at proto.utf8Write (node:internal/buffer:1066:13)
    at Op.writeStringBuffer [as fn] (/Users/dlarocque/workspace/repro/nodebug/node_modules/protobufjs/src/writer_buffer.js:61:13)
    at BufferWriter.finish (/Users/dlarocque/workspace/repro/nodebug/node_modules/protobufjs/src/writer.js:453:14)
    at /Users/dlarocque/workspace/repro/nodebug/node_modules/@grpc/proto-loader/build/src/index.js:177:109
    at Array.map (<anonymous>)
    at createPackageDefinition (/Users/dlarocque/workspace/repro/nodebug/node_modules/@grpc/proto-loader/build/src/index.js:177:39)
    at Module.fromJSON (/Users/dlarocque/workspace/repro/nodebug/node_modules/@grpc/proto-loader/build/src/index.js:230:12)
    at loadProtos (file:///Users/dlarocque/workspace/repro/nodebug/node_modules/@firebase/firestore/dist/index.node.mjs:22129:43)
    at newConnection (file:///Users/dlarocque/workspace/repro/nodebug/node_modules/@firebase/firestore/dist/index.node.mjs:22151:20)
    at OnlineComponentProvider.createDatastore (file:///Users/dlarocque/workspace/repro/nodebug/node_modules/@firebase/firestore/dist/index.node.mjs:26266:28) {
  code: 'ERR_BUFFER_OUT_OF_BOUNDS'
}

Node.js v22.7.0

@dlarocque
Copy link
Contributor

Looks like this new line added to node in 22.7 is what's throwing the error https://github.com/nodejs/node/pull/54311/files#diff-ec53d27b3c64c43cc2d4773dd88046ebb149e3d89e31d838df3252c8d5de89adR1066

@blackazaru
Copy link

This is happening and has already happened several times on:

Firebase CLI: 13.15.4
firebase-admin: 11.10.1
Node.js: 20.10"

@lucasmengarda
Copy link
Author

I got caught off guard. I was using FROM node:latest in my Docker for the dev environment, and suddenly the whole system started failing with the error RangeError [ERR_BUFFER_OUT_OF_BOUNDS].

Spent a few hours figuring out the issue, but I switched the Dockerfile to FROM node:lts and everything's back to normal.

Probably is a Node bug.

@dlarocque
Copy link
Contributor

I got caught off guard. I was using FROM node:latest in my Docker for the dev environment, and suddenly the whole system started failing with the error RangeError [ERR_BUFFER_OUT_OF_BOUNDS].

Spent a few hours figuring out the issue, but I switched the Dockerfile to FROM node:lts and everything's back to normal.

Probably is a Node bug.

Do you happen to be using protobufjs or grpc?

@dlarocque
Copy link
Contributor

This is a Node bug, and was fixed here: nodejs/node#54526

@lucasmengarda
Copy link
Author

Thanks bud

@dlarocque dlarocque removed the bug label Aug 27, 2024
@firebase firebase locked and limited conversation to collaborators Sep 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants