'Calling Firebase cloud function causes DEADLINE_EXCEEDED error when using Firebase emulator

I've got a very simple cloud function that returns a string in a JSON.

const functions = require("firebase-functions");

// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions

exports.helloWorld = functions.https.onRequest((request, response) => {
  functions.logger.info("Hello logs!", {structuredData: true});
  response.send({data: "Hello from Firebase!"});
});

And I am calling it like this(app is running in android emulator):

async function callFirebaseCloudFunction() {
    try
    {

        functions().useEmulator('localhost', 5001);
        

        const helloWorldFunction = functions().httpsCallable('abcd');
        const response = await helloWorldFunction();
        console.log(response?.data);
        alert(response?.data);
    }
    catch (error)
    {
        console.log("====",error);
        alert(`${JSON.stringify(error)}` );

    }
}

The issue is that I am getting DEADLINE_EXCEEDED error.

Note that I am also running firebase's emulator for cloud function, therefore this line: functions().useEmulator('localhost', 5001);

Otherwise, commenting the above line and calling the deployed function works fine.



Solution 1:[1]

After spending more than an hour, and writing this question. I finally figured out the problem(kind of), so I thought I should just answer it.

I was using the android emulator of Genymotion, and the request kept failing "DEADLINE_EXCEEDED" error. When I used avd(android virtual device from Android Studio), it worked totally fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tayyab Mazhar