javascriptnode.jsfirebasegoogle-cloud-platformgoogle-cloud-firestore

Google Cloud Run Firestore: [ERR_BUFFER_OUT_OF_BOUNDS]: "length" is outside of buffer bounds


I'm using the Google Cloud Run Firestore integration, which worked fine until recently. I can't do any CRUD operations aynmore, while I'm able to authenticate.

This only occurs on the Google Cloud Run instance but not when I connect to the same database locally (with a service account).

The error is:

2024-08-23 10:19:55.857 CEST
Caused by: Error
2024-08-23 10:19:55.857 CEST
    at Firestore.getAll (/home/node/app/node_modules/@google-cloud/firestore/build/src/index.js:1007:23)
2024-08-23 10:19:55.857 CEST
    at DocumentReference.get (/home/node/app/node_modules/@google-cloud/firestore/build/src/reference/document-reference.js:180:32)
2024-08-23 10:19:55.857 CEST
    at compareCredentials (file:///home/node/app/auth.js:55:40)
2024-08-23 10:19:55.857 CEST
    at authenticate (file:///home/node/app/auth.js:200:16)
2024-08-23 10:19:55.857 CEST
    at postAuthAdmin (file:///home/node/app/routes.js:354:37)
2024-08-23 10:19:55.857 CEST
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
2024-08-23 10:19:55.857 CEST
    at async Server.server (file:///home/node/app/server.js:173:15) {
2024-08-23 10:19:55.857 CEST
  code: 'ERR_BUFFER_OUT_OF_BOUNDS'
2024-08-23 10:19:55.857 CEST
}

And the code:

const firestore = new Firestore({ databaseId: 'projecttest' })

const credsColl = firestore.collection('creds')
const adminCredsDoc = credsColl.doc('admin')

const adminDoc = await adminCredsDoc.get() // ERR_BUFFER_OUT_OF_BOUNDS

The document I'm trying to get (password is faked):

{
    user: 'admin',
    password: '$2a$12$kHkqVa3fHz7qRBpv5BSPCOjci1H77AGHNXsReL3Huw9vITk5lqcXG'
}

Solution

  • Which version of Node are you running? I had the same issue with the latest version 22.7.0 and downgraded to the one I used before, 22.5.0. That worked.

    Please check also the issue I filed here:

    https://github.com/nodejs/node/issues/54518

    EDIT:

    The issue has been addressed and will be fixed in version 22.8.0: https://github.com/nodejs/node/issues/54518#issuecomment-2307687124