firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.78k stars 876 forks source link

callAtURL > functionsInstance.contextProvider.getContext never returns #8267

Closed daedwards767 closed 1 month ago

daedwards767 commented 1 month ago

Operating System

Windows 11 Home 23H2

Browser Version

Google Chrome Version 124.0.6367.208

Firebase SDK Version

10.11.0

Firebase SDK Product:

Functions

Describe your project's tooling

React app with Webpack and Jest

Describe the problem

I'm trying to call a callable function. but the client cannot reach the cloud function code.

This is because the code hangs at @firebase/functions/src/service.ts > callAtURL (line 280): const context = await functionsInstance.contextProvider.getContext( options.limitedUseAppCheckTokens );

As a result, the network call is never made.

I can hit the function on the server using a barebones fetch or Postman, and it works perfectly.

I've posted about this issue on Stackoverflow previously: https://stackoverflow.com/questions/77122626/firebase-callable-functions-not-making-a-network-call-from-frontend-promise-nev

Steps and code to reproduce issue

I'm not certain why this happened in my environment. My reproduction steps are

  1. create a new project
  2. download firebase^@10.11.0
  3. write and deploy a callable function, on the server
  4. import httpsCallable on the client
  5. attempt to call the server from the client via the httpsCallable

Result: the code hangs and never returns. No network call is made.

My code: CLIENT import { getFunctions, httpsCallable } from "firebase/functions"; const functions = getFunctions(firebaseApp); const viewInvoice = httpsCallable(functions, 'testOnCall'); const result = await viewInvoice({ "test": "testy" })

BACKEND const { onCall } = require("firebase-functions/v2/https"); exports.testOnCall = onCall((request) => { console.log("request is ", request) return true
})

google-oss-bot commented 1 month ago

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

jbalidiong commented 1 month ago

Hi @daedwards767, apologies for the delay. I tried replicating the behavior but I wasn't able to replicate it. Using the code and version stated above, I was able to get a response to the function. I tried using the emulator and deploying the function and the behavior is consistent on my end. Can you provide a minimal repro project that I can run locally.

google-oss-bot commented 1 month ago

Hey @daedwards767. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

hsubox76 commented 1 month ago

We should double check what could make getContext hang instead of no-op if it can't find an app check instance/token or something - some environment issue. You said you're using Jest in your stack. Is this failing/hanging in Jest or is Jest just something else you have in your project but aren't using when you get this particular error? Sounds like you have an error in your app code, not during a test?

Edit: Sounds like it's hanging when trying to get the authToken, messagingToken, or appCheckToken - all of these are promises and designed to no-op gracefully if any of them are unavailable. Not sure which one is hanging and difficult to narrow it down to one without a repro. https://github.com/firebase/firebase-js-sdk/blob/master/packages/functions/src/context.ts#L140

Any information about the environment would help - any ad blockers, proxy, privacy settings, frameworks, etc.

daedwards767 commented 1 month ago

Sorry for the delay. I've just tried to reproduce the error to give you additional information and the same code above now works. I'm baffled as I've had this issue for a while (you can see from my SO post). There is no more hanging, and it works as expected. Sorry for any confusion or wasted effort.