question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
hiranya911commented, Jul 6, 2020

Ok, that forum post actually helped.

This is often resolved by changing the function code to include calls to close “the connection”. As far as what “the connection” actually is, it is typically a connection to an API or database.

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#delete

This is not required in most environments. But it appears it’s required in Netlify.

0reactions
alexanvlcommented, Sep 23, 2022

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 to false seems to resolve the issue and we’re try to determine what caused it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found