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

ECONNRESET #1695

Closed
Jared00m opened this issue Nov 26, 2023 · 5 comments
Closed

ECONNRESET #1695

Jared00m opened this issue Nov 26, 2023 · 5 comments
Assignees
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@Jared00m
Copy link

Jared00m commented Nov 26, 2023

I have been working on a Flutter project that uses Firebase Functions. In the past, I was able to create a Firebase Function that retrieves a JWT access token with no problem. However, recently, I get the following error every time:

{"severity":"ERROR","message":"Unhandled error GaxiosError: Invalid response body while trying to fetch https://www.googleapis.com/oauth2/v4/token: read ECONNRESET\n

Here is my code:

import { JWT } from "google-auth-library";
import fs from "fs";
import * as functions from "firebase-functions";
const logger = functions.logger;

export const getJSONWebToken = functions.https.onCall(async (data, context) => {
  try {
    const keyFile = "./src/secrets/***************************";

    const keys = JSON.parse(fs.readFileSync(keyFile, "utf8"));

    const client = new JWT({
      email: keys.client_email,
      key: keys.private_key,
      scopes: ["https://www.googleapis.com/auth/cloud-platform"],
    });

    const url = `https://dns.googleapis.com/dns/v1/projects/${keys.project_id}`;
    await client.request({ url });

    const res = await client.getAccessToken();

    if (res.token) {
      return { token: res.token };
    } else {
      console.log("no token retrieved");
      return { token: "no token " };
    }
  } catch (error) {
    logger.error(error);
    throw error;
  }
});

Any help would be greatly appreciated. I'm not a professional coder and I'm new to Firebase and Flutter.

@Jared00m Jared00m added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Nov 26, 2023
@danielbankhead danielbankhead self-assigned this Nov 28, 2023
@danielbankhead
Copy link
Contributor

@Jared00m which version of Node are you running?

@Jared00m
Copy link
Author

Jared00m commented Nov 29, 2023

@danielbankhead , thanks for asking. I've tried it on Node 18, 16, 15, 14, and 12.

On node 15 I get a useful error that says:


data: {
      error: {
        code: 403,
        message: 'Forbidden',
        errors: [
          {
            message: 'Forbidden',
            domain: 'global',
            reason: 'forbidden'
          }
        ]
      }
    },

On Node 18 I get this error:


config: {
    method: 'POST',
    url: 'https://www.googleapis.com/oauth2/v4/token',
    data: {
      grant_type: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
      assertion: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.'
    },
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'User-Agent': 'google-api-nodejs-client/9.2.0',
      'x-goog-api-client': 'gl-node/18.3.0',
      Accept: 'application/json'
    },
    responseType: 'json',
    paramsSerializer: [Function: paramsSerializer],
    body: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
    validateStatus: [Function: validateStatus],
    errorRedactor: [Function: defaultErrorRedactor]
  },
  response: undefined,
  error: FetchError: Invalid response body while trying to fetch https://www.googleapis.com/oauth2/v4/token: read ECONNRESET
      at Gunzip.<anonymous> (/Users/jared/Coding/language-app-test/language-app/functions/node_modules/node-fetch/lib/index.js:400:12)
      at Gunzip.emit (node:events:539:35)
      at emitErrorNT (node:internal/streams/destroy:151:8)
      at emitErrorCloseNT (node:internal/streams/destroy:116:3)
      at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
    type: 'system',
    errno: 'ECONNRESET',
    code: 'ECONNRESET'
  },
  code: 'ECONNRESET'
}

@danielbankhead danielbankhead added the status: investigating The issue is under investigation, which is determined to be non-trivial. label Nov 29, 2023
@danielbankhead
Copy link
Contributor

@danielbankhead danielbankhead removed the status: investigating The issue is under investigation, which is determined to be non-trivial. label Dec 5, 2023
@danielbankhead
Copy link
Contributor

After discussing with the team, this is best handled by setting up automatic retries in this library.

I'll prioritize this work and it can be tracked here:

@danielbankhead danielbankhead closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2023
@danielbankhead
Copy link
Contributor

This PR should provide some relief for the immediate issue:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants