Skip to content

http2 error: stream error received: unspecific protocol error detected #369

@Jonny1987

Description

@Jonny1987

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I get the following error in my edge function:

Error: request to https://www.googleapis.com/oauth2/v4/token failed, reason: error sending request for url (https://www.googleapis.com/oauth2/v4/token): http2 error: stream error received: unspecific protocol error detected
    at Gaxios._request (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/gaxios/6.5.0/build/src/gaxios.js:143:19)
    at eventLoopTick (ext:core/01_core.js:168:7)
    at async GoogleToken._GoogleToken_requestToken (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/gtoken/7.1.0/build/src/index.js:241:19)
    at async GoogleToken._GoogleToken_getTokenAsync (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/gtoken/7.1.0/build/src/index.js:160:16)
    at async JWT.refreshTokenNoCache (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/google-auth-library/9.8.0/build/src/auth/jwtclient.js:173:23)
    at async JWT.authorizeAsync (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/google-auth-library/9.8.0/build/src/auth/jwtclient.js:154:24) {
  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.8.0",
      "x-goog-api-client": "gl-node/20.11.1",
      Accept: "application/json"
    },
    responseType: "json",
    retryConfig: {
      httpMethodsToRetry: [ "POST" ],
      currentRetryAttempt: 2,
      retry: 3,
      noResponseRetries: 2,
      statusCodesToRetry: [ [ 100, 199 ], [ 408, 408 ], [ 429, 429 ], [ 500, 599 ] ]
    },
    paramsSerializer: [Function: paramsSerializer],
    body: "<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.",
    validateStatus: [Function: validateStatus],
    errorRedactor: [Function: defaultErrorRedactor]
  },
  response: undefined,
  error: FetchError: request to https://www.googleapis.com/oauth2/v4/token failed, reason: error sending request for url (https://www.googleapis.com/oauth2/v4/token): http2 error: stream error received: unspecific protocol error detected
    at HttpsClientRequest.<anonymous> (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/node-fetch/2.7.0/lib/index.js:1501:11)
    at HttpsClientRequest.emit (ext:deno_node/_stream.mjs:1851:9)
    at node:http:467:16
    at eventLoopTick (ext:core/01_core.js:168:7) {
    message: "request to https://www.googleapis.com/oauth2/v4/token failed, reason: error sending request for url "... 116 more characters,
    type: "system",
    errno: undefined,
    code: undefined
  },
  [Symbol("gaxios-gaxios-error")]: "6.5.0"
}

To Reproduce

Create an edge function which contains the following code (service-account.json which downloaded from firebase when creating a new private key):

import { JWT } from "npm:google-auth-library@9";

const getAccessToken = (
  { clientEmail, privateKey }: { clientEmail: string; privateKey: string },
): Promise<string> => {
  return new Promise((resolve, reject) => {
    const jwtClient = new JWT({
      email: clientEmail,
      key: privateKey,
      scopes: ["https://www.googleapis.com/auth/firebase.messaging"],
    });
    jwtClient.authorize((err, token) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(token!.access_token!);
    });
  });
};

  const { default: serviceAccount } = await import("../service-account.json", {
    with: { type: "json" },
  });

  const accessToken = await getAccessToken({
    clientEmail: serviceAccount.client_email,
    privateKey: serviceAccount.private_key,
  });

Expected behavior

No error

Screenshots

If applicable, add screenshots to help explain your problem.

System information

Additional context

No change to my edge function has occured and the error started sometime between 10th June and 18th June (my edge function was not run between these dates)

I have tried downgrading google-auth-library (versions 9.10 down to 9.0) but error still occured.

I have also run this code locally using the latest version of deno (1.44.2) and deno version 1.43.0 (same as current supabase edge-runtime) and no error occurs

Metadata

Metadata

Assignees

Labels

C-bugCategory: something isn't workingreleased

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions