Server:
exports.outerMainFunction = functions
.runWith({
timeoutSeconds: 540,
})
.https.onCall(
async (request, context) => {
return new Promise(async function (resolve) {
try {
let resp = await innerFunc()
console.log("resp == ", JSON.stringify(resp))
return resolve({
status: 'success'
})
} catch (err) {
return resolve({
status: 'error'
})
}
})
}
)
module.exports.innerFunc = () => {
return new Promise((resolve) => {
let targetAudience = '' // url to the inner java cloud function
const auth = new GoogleAuth()
async function innerFunction() {
const client = await auth.getIdTokenClient(targetAudience)
const requestOptions = {
url: targetAudience,
method: 'POST',
headers: {
'Content-Type': '',
},
data: {},
timeout: 300000,
}
console.log('Inside innerFunction: caling CF')
const res = await client.request(requestOptions)
return res
}
return innerFunction()
.then(function (response) {
let finalResp = JSON.parse(response.data)
return resolve({ status: 'success in inner', result: finalResp })
})
.catch(function (error) {
return resolve({ status: 'error in inner' })
})
})
}
Console:
const getFuncDetails = async () => {
try {
let data = {}
let res = httpsCallable(getFunctions(), 'outerMainFunction')
let result = await res(data)
return result
} catch (err) {
console.log('Error while getting the details: ', JSON.stringify(err))
return { status: 'error' }
}
}
This is the code I have written. I am calling outerMainFunction from console side. The call is going through.
On the server end outerMainFunction is calling innerFunc. innerFunc is a java cloud function. If innerFunction is taking more than one minute to send the response, although on the server end I see proper logs with success status, on the console end getFuncDetails is going into catch block with the below error:
{“code”:”functions/deadline-exceeded”,”name”:”FirebaseError”}
I have given the below configurations for each function:
outerMainFunction – 512 mb with 540 sec timeout
innerFunction – 2gb with 540 sec timeout
Only when innerFunction is taking more than 1 minute to respond, I am facing this issue. How do I fix it?
I don’t see any issue with the timeout, not sure why it is not waiting.
I even tried logging some console logs and even reading/writing from firebase during the waiting time to not keep it idle but it’s not helping.
Also, since the error is seen on the console end, not sure what change needs to be done.
I even checked that default timeout might be 60 sec but when I go and list the cloud functions in cloud console, the above mentioned configurations are seen.
What else can be done to fix the issue?
Should I try converting the main function to express or change it to gen2? I am not sure if it’ll be helpful.
Any suggestion would be appreciated.