denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.18k stars 5.4k forks source link

node:http2 stream error when using npm:firebase-admin #25065

Open FredslundMagnus opened 3 months ago

FredslundMagnus commented 3 months ago

I ran the same code maybe 2-4 weeks ago on deno deploy and it worked, but now I run it from my own server and get this error: I saw similar issues raised (error with node:http2) before like this but not the same error message.

I run with -A --unstable-kv --unstable-cron and i tried with just --unstable but it did also not work

and i use fresh: "$fresh/": "https://deno.land/x/fresh@1.6.8/",

Not sure if relevant but i have deno to output to port 8000, and then i ran:

iptables -t nat -A OUTPUT -o lo -p tcp --dport 443 -j REDIRECT --to-port 8080

And I have secure connection.

Version: Deno 1.45.5

import admin from "npm:firebase-admin";
import serviceAccount from "...[file path]..." with { type: "json" };

// Init
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount as admin.ServiceAccount)
});

// In some function later in the file
async function f() {
  const messages = [
    {
      token: "......[the actual token].....",
      notification: {
        title: "...[some title]...",
        body: "...[some text]..."
      },
      data: { surveys: "...[some data]..." }
    }
  ]

  await admin.messaging().sendEach(messages); // This errors
}
error: Uncaught (in promise) Error: stream error received: unspecific protocol error detected
    at node:http2:735:50
    at ClientHttp2Stream._read (node:http2:761:7)
    at ClientHttp2Stream.Readable.read (ext:deno_node/_stream.mjs:2996:16)
    at resume_ (ext:deno_node/_stream.mjs:3346:16)
    at processTicksAndRejections (ext:deno_node/_next_tick.ts:33:15)
    at runNextTicks (ext:deno_node/_next_tick.ts:71:3)
    at eventLoopTick (ext:core/01_core.js:175:21)
FredslundMagnus commented 3 months ago

I get a new error with deno 1.46.1 (stable, release, x86_64-unknown-linux-gnu)

It successfully sends the messages, and the error is thrown much later


async function f() {
  // ...

  try {
    const res = await admin.messaging().sendEach(messages);
    console.log({ failures: res.failureCount, successes: res.successCount }); // 0 failures
  } catch (e) {
    console.error(e); // No error
  }
}

Deno.cron("Create survey instances", { minute: { every: 15 } }, async () => {
  try {
    await f();
  } catch (e) {
    console.error(e); // No error here
  }

  console.log("End of cron"); // This prints
});

But after some time (counted it to around 15 seconds) it throws this error (and crashes the deno process/quits the program):

error: Uncaught Error: Not implemented: callTimeout
    at notImplemented (ext:deno_node/_utils.ts:9:9)
    at callTimeout (node:http2:1045:3)
    at ClientHttp2Stream._onTimeout (node:http2:734:5)
    at cb (ext:deno_node/internal/timers.mjs:64:31)
    at eventLoopTick (ext:core/01_core.js:209:13)

The error is not thrown if I comment out these line:

    // const res = await admin.messaging().sendEach(messages);
    // console.log({ failures: res.failureCount, successes: res.successCount }); // 0 failures

But nice progress! Is there any way to catch the error until it is fixed, so the program won't crash?

FredslundMagnus commented 3 weeks ago

This bug still exists in Deno 2.0.5