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

[Firestore] grpc error on Bun standalone executable file #2744

Open
mavyfaby opened this issue Oct 28, 2024 · 5 comments
Open

[Firestore] grpc error on Bun standalone executable file #2744

mavyfaby opened this issue Oct 28, 2024 · 5 comments
Assignees

Comments

@mavyfaby
Copy link

Environment

  • Bun Version: v1.1.33
  • Operating System version: Linux 6.8.0-47-generic (Ubuntu)
  • Firebase SDK version: firebase-admin@12.7.0
  • Firebase Product: Firestore

Description

I'm using firestore and it works when using bun src/index.ts but not when using single executable file.

NODE_ENV=production bun build --compile --sourcemap --minify ./src/index.ts --outfile app

and this happens when executing a firestore code, for instance this one:

 await firestore.collection("customers").doc(fbaseId).set({
    data1: "ex1",
    data2: "ex2"
 });

and the error:

 26 |  * error is not necessarily a problem in gRPC itself.
 27 |  * @param status
 28 |  */
 29 | function callErrorFromStatus(status, callerStack) {
 30 |     const message = `${status.code} ${constants_1.Status[status.code]}: ${status.details}`;
 31 |     const error = new Error(message);
                            ^
 error: undefined undefined: undefined
       at X$f (node_modules/@grpc/grpc-js/build/src/call.js:31:23)
       at onReceiveStatus (node_modules/@grpc/grpc-js/build/src/client.js:193:56)
       at onReceiveStatus (node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
       at onReceiveStatus (node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
       at node_modules/@grpc/grpc-js/build/src/resolving-call.js:129:78
       at processTicksAndRejections (native:7:39)
       at makeUnaryRequest (node_modules/@grpc/grpc-js/build/src/client.js:161:32)
       at v (node_modules/google-gax/build/src/normalCalls/retries.js:81:81)
       at node_modules/google-gax/build/src/normalCalls/retries.js:125:13
       at call (node_modules/google-gax/build/src/call.js:67:27)
       at call (node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19)
       at node_modules/google-gax/build/src/createApiCall.js:112:30
       at processTicksAndRejections (unknown:7:39)
       at commit (node_modules/@google-cloud/firestore/build/src/write-batch.js:436:23)
       at set (node_modules/@google-cloud/firestore/build/src/reference/document-reference.js:344:27)
       at src/api/customers/register.ts:80:58
       at processTicksAndRejections (native:7:39)
@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@mavyfaby
Copy link
Author

cc: @cirospaciari

@mavyfaby mavyfaby changed the title [Firestore] grpc error on standalone executable file [Firestore] grpc error on Bun standalone executable file Oct 28, 2024
@dconeybe dconeybe self-assigned this Oct 28, 2024
@dconeybe
Copy link

Note that Bun is not an officially-supported runtime, although it has been repeatedly requested and is on our radar: #2572

Notably, grpc is known to not work on Bun. Some customers have reported success using the "preferRest" option:

const firestore = initializeFirestore(app, {
  preferRest: true,
});

This causes the network stack to use simple HTTP requests when communicating with the backend, eliding grpc. Note, however, that "rest" does not support streaming, so adding a snapshot listener will try to "upgrade" the connection to grpc, which will likely result in the error that you reported. But as long as you don't need realtime updates, preferRest may help resolve your issue.

Unfortunatley, I cannot make any commitments as to a fix due to its lack of official support. If you find some low-hanging fruit in the https://github.com/googleapis/nodejs-firestore SDK then I'd be open to review a pull request.

@Jarred-Sumner
Copy link

Notably, grpc is known to not work on Bun. Some customers have reported success using the "preferRest" option:

In Bun v1.1.32, we added server support for our node:http2 implementation and pass almost all of Node.js' http2 tests. We also now run grpc-js's test suite on every commit and 95.25% pass. The failing tests are mostly related to http2 push or the http1 fallback.

Please let us know if you continue to run into issues with gRPC, Firebase, or Firestore in Bun (and file issues in our repo). If it works in Node and doesn't work in Bun, it is a bug in Bun.

In this particular issue's case, this appears to be a bundler bug (bun build --compile runs the bundler). One thing you could try: bun build --compile --format=cjs <file>. This will use CommonJS instead of ESM as the entry point, which might help here.

@dconeybe
Copy link

Hi @Jarred-Sumner! Thank you for chiming in and providing a suggestion. I'll admit, it's been a while since I tried Firestore with grpc in Bun, and I have very minimal experience with Bun. Again, the team's current priorities don't include Bun support, although I can say we've received a strong demand for it so it is on our radar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants