Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication error in tasks firebase emulator on enqueue #2754

Open
jootten opened this issue Nov 4, 2024 · 0 comments
Open

Authentication error in tasks firebase emulator on enqueue #2754

jootten opened this issue Nov 4, 2024 · 0 comments
Assignees

Comments

@jootten
Copy link

jootten commented Nov 4, 2024

Environment

  • Operating System version: Fedora Linux 40
  • Firebase SDK version: 6.0.1
  • Firebase Product: auth, tasks, emulator
  • Node.js version: 18
  • NPM version: 10.2.3
  • Firebase Tools: 13.23.1

Problem

Authentication fails in the firebase tasks emulator on

await queue.enqueue(...)  \\ full sample below

with the following error:
Error scheduling task FirebaseAppError: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND".

We were able to reproduce the bug reported here firebase/firebase-tools#7821 with the latest SDK and firebase tools versions.

The error does not occur when application default credentials are available and is thus easily overlooked.

Steps to reproduce:

  1. Setup firebase project as in Cloud Tasks Emulator Error: Error fetching access token: invalid_grant (reauth related error (invalid_rapt)) firebase-tools#7821.
  2. Start the emulator with the code below.
npm run build && npx firebase emulators:start --project='demo-project' --debug
  1. Enqueue a task by executing the testOnRequest function (http://127.0.0.1:5001/demo-project/us-central1/testOnRequest).

emulator-debug.log

Relevant Code:

Reproducible example that is even more minimal than in the mentioned issue:

import { onRequest } from "firebase-functions/v2/https";
import { getFunctions } from "firebase-admin/functions";
import { onTaskDispatched } from "firebase-functions/v2/tasks";
import * as logger from "firebase-functions/logger";
import { initializeApp } from "firebase-admin/app";

// Initialize the Firebase app
initializeApp()

// The http function
export const testOnRequest = onRequest(async (request, response) => {
  const taskPayload = {
    foo: "bar",
  };

  const taskFunctionName = `testOnTaskDispatched`;
  const queue = getFunctions().taskQueue(taskFunctionName);

  try {
    await queue.enqueue(taskPayload);
    response.send("Success. Hello from HTTP onRequest!");
  } catch (error) {
    console.error("Error scheduling task", error);
    response.status(500).send("Error scheduling task");
    return;
  }
});

// The task function
export const testOnTaskDispatched = onTaskDispatched( (request) => {
  logger.info("Success. Hello logs from TASKS onTaskDispatched!", {
    foo: request.data,
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants