firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Firestore lite: RestConnection RPC [FirebaseError: Request failed with error: undefined]

Open jpreynat opened this issue 1 year ago • 6 comments

[REQUIRED] Describe your environment

  • Operating System version: Ubuntu 18.04 (Cloud Functions Node 16)
  • Browser version: N/A (Running on Cloud Functions with Node 16)
  • Firebase SDK version: 9.19.1
  • Firebase Product: firestore/lite

[REQUIRED] Describe the problem

We recently just tried to switch our production application to use firestore/lite instead of the complete Firestore SDK in our Cloud Functions. Now, every once in a while, Firestore throws errors in this form:

@firebase/firestore: Firestore (9.19.1_lite): RestConnection RPC 'BatchGetDocuments' 0x11d7c49f failed with error:  [FirebaseError: Request failed with error: undefined]

This can happen for read and for write operations, but very very rarely. We never had such issues before switching to firestore/lite. The undefined error also makes it impossible to debug.

Steps to reproduce:

Use firestore/lite in Cloud Functions.

jpreynat avatar Apr 21 '23 10:04 jpreynat

Thanks for the report.

I am a little curious to your use case that you use the lite sdk in cloud functions. Is there any reason why you ruled out our admin/server SDK that are design for running on the backend.

Lite SDK is intended for web apps that are sensitive to bundle sizes, running from a browser. That does not explain the error you see, but I suspect not many people are doing this.

wu-hui avatar Apr 21 '23 15:04 wu-hui

Hi @wu-hui 👋

For the context, it was initially more of an experimentation, because we are planning on deploying part of the same codebase that runs currently on Cloud Functions to edge runtimes, like Cloudflare Workers runtime or Vercel Edge runtime, for which the native Node SDK doesn’t work. While rollbacking to using the Node SDK in Cloud Functions is obviously still an option, we’d prefer to stick with the lite version here too, as we equally don’t need listeners in this environment, and it would allow for a lighter implementation, with potentially some gain on the cold starts time.

Regarding the issue, we’ve been successfully running our staging environment with the lite version before deploying in production, and as I mentioned, this seems to happen in very rare cases, because I’d say that it’s working fine for ~99+% of the executions. It seems however that this error happens mostly when there is lots of concurrent requests for large objects in our backend, for instance fetching more than 20/30 objects at the same time, or many documents that are close to the 1MB size limit.

Since the returned error is just undefined, it makes it very hard to pinpoint where things or what go(es) wrong.

jpreynat avatar Apr 22 '23 15:04 jpreynat

I am not an expert with edge runtimes..what are the blockers to running Node in those environment? Is it mainly the slow bootstrap time? You might be aware of this already, our Node sdk can use rest connections as well.

wu-hui avatar Apr 25 '23 14:04 wu-hui

@wu-hui this happens to me with "firebase": "9.22.1". I'm running jest tests.

iSuslov avatar May 27 '23 08:05 iSuslov

Having the same problem, switching require("firebase/firestore/lite"); to require("firebase/firestore"); no longer has the problem.

nojaf avatar Jun 10 '23 08:06 nojaf

I have also been seeing the same error, using Firestore Lite in a web app for simple requests such as getting a record.

I'm only seeing this happen in the emulator, not in production.

Changing to Firestore solves it (but would prefer to use Lite for the smaller file sizes).

I'm on the latest version of the Firebase package, running on Node 20.

joefhall avatar Mar 13 '24 10:03 joefhall