invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.55k stars 2.19k forks source link

Callable Functions timeout issue #1979

Closed aliozinan closed 5 years ago

aliozinan commented 5 years ago

Issue

:fire:

Callable functions are returning HttpsError: timeout. The reason of the issue is the default 10 seconds limitation of the Java library used for HTTP requests. If a callable function runs over 10 seconds, even it goes on running and completes its job on Firebase server, the library throws timeout error on the client side. I raised a request to the Google Cloud Team long time ago but it's still not resolved. A workaround solution has been provided below, which could be considered to be implemented :

https://stackoverflow.com/questions/50971356/firebase-cloud-functions-change-timeout


Project Files

iOS

ios/Podfile:

N/A

AppDelegate.m:

N/A

Android

android/build.gradle:

N/A

android/app/build.gradle:

N/A

android/settings.gradle:

N/A

MainApplication.java:

N/A

AndroidManifest.xml:

N/A

Environment

aliozinan commented 5 years ago

Update

firebase-functions version 16.3.0, released 15 Mar 2019, adds the ability to configure the timeout.

https://firebase.google.com/docs/reference/android/com/google/firebase/functions/HttpsCallableReference

Looks like the Google Team came up with a solution and set the default timeout to 60 seconds for callable functions. I'll be sharing the test results here.

stale[bot] commented 5 years ago

Hello 👋, this issue has been automatically marked as stale because it has not had activity for quite some time. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 5 years ago

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

bitfabrikken commented 5 years ago

@aliozinan any news? I'm also stuck with the 10 second timeout here and am wondering if you learned something new?

bsendras commented 5 years ago

@bitfabrikken Here is a workaround for this issue. Since the limitation is within the library for HTTP requests used by react-native-firebase, we tried to use another one. So instead of use functions().httpsCallable(), we decided to call the function with a http client like axios.

We were concerned about authentication, because if you call the function in this way, the function won't receive the context object. Hopefully, firebase automaticaly validates a bearer token that you can provide in the Authorization header, and populates the context object.

Here's my example

import { auth } from 'react-native-firebase';
import axios from 'axios';

export const functionsHttpCallable = async () => {
   // Get the token for the logged user
   const token = await auth().currentUser.getIdToken();

   // Do the request
   return axios.post(
       '<Your Firebase Cloud Function URL>',
       {
          data: { 'parameters of the function' }
       },
       {
          headers: {
             'Content-Type': 'application/json',
             // This will be automatically validated in the server
             Authorization: `Bearer ${token}`
          },
          transformResponse: [
             response => {
                const res = JSON.parse(response);
                // unwrap the object returned by the function
                return res.result;
              }
          ]
       }
   );
}

You can parametrize that function with the name of the cloud function, the token, and the parameters to send.

Hope it helps!

aliozinan commented 5 years ago

It seems like Google's update I mentioned above must be implemented on react-native-firebase side as well. Now that there's the timeout parameter available for HttpsCallableReference, the team can do something about it I guess?

mikehardy commented 5 years ago

@aliozinan PRs are welcome if you’d like to propose one

mikehardy commented 5 years ago

it does seem valid to re-open this one as no longer blocked though?

aliozinan commented 5 years ago

@aliozinan PRs are welcome if you’d like to propose one

I would love to, if I knew how to code Java

it does seem valid to re-open this one as no longer blocked though?

Yes this issue is still unresolved and needs to be re-opened. It was closed by the bot, I cannot re-open it.