Using verifyIdToken()` with the second argument causes serverless function to timeout
See original GitHub issue- Operating System version: Ubuntu Xenial 16.04
- Firebase SDK version: 8.13.0
- Firebase Product: auth
- Node.js version: v12.18.0
- NPM version: 6.14.4
Steps to reproduce:
Using verifyIdToken(idToken, true)
with the second argument to check if the token has been revoked causes Netlify serverless Function to timeout.
Relevant Code:
Publish the following code below to a Netlify function, then hit the endpoint which includes a valid JWT with an “Authorization” header and the lambda function will consistently timeout.
However if you remove the second argument from verifyIdToken()
and republish the function again, there are no issue at all.
const admin = require("firebase-admin")
const SERVICE_ACCOUNT = JSON.parse(process.env.FIREBASE_CONFIG);
if (!admin.apps.length) {
admin.initializeApp({
credential: admin.credential.cert(SERVICE_ACCOUNT)
});
}
exports.handler = async function (event, context, callback) {
try {
// Extract JWT from header
const JWT = event.headers.authorization;
// Verify JWT, if user deleted, or JWT is invalid, this will throw an error
const user = await admin.auth().verifyIdToken(JWT, true);
callback(null, {
statusCode: 200,
headers: { "Content-Type": "application/json" },
body: JSON.stringify(user)
});
} catch (error) {
console.error("There was an error", error);
callback(null, {
statusCode: 400,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ error })
});
}
};
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
AWS Lambda Functions - Serverless Framework
All of the Lambda functions in your serverless service can be found in serverless.yml under the ... timeout: 10 # optional, in seconds,...
Read more >Troubleshoot Lambda function retry and timeout issues ... - AWS
There are three reasons why retry and timeout issues occur when invoking a Lambda function with an AWS SDK:.
Read more >How to handle timeouts in Lambda functions
Lambda function timeouts. A Lambda function has a timeout parameter after which the Lambda runtime terminates the execution.
Read more >Admin SDK error handling - Firebase - Google
If the getUserInput() method returns null or empty strings, ... They return true if the input argument actually contains the error code in...
Read more >AWS lambda function stops working after timed out error
I experienced the three second timeout error when I had my require statements in the body of exports.handler instead of at the top...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, that forum post actually helped.
You need to clean up the App instance (
app.delete()
) to ensure proper clean up of the Admin SDK: https://firebase.google.com/docs/reference/admin/node/admin.app.App#deleteThis is not required in most environments. But it appears it’s required in Netlify.
We started to see this error at 2022-09-23 09:49:08.055 PDT in the firebase-admin@11.0.1 package, running in a node:16 container within GKE. Setting the
checkedRevoked
parameter tofalse
seems to resolve the issue and we’re try to determine what caused it.