Skip to content

When use the realtime database in Deno, it never finishes running #5783

@ayame113

Description

@ayame113

[REQUIRED] Describe your environment

  • Operating System version: Microsoft Windows [Version 10.0.19042.1348]
  • Browser version: Deno 1.16.3
  • Firebase SDK version: 9.6.0
  • Firebase Product: realtime database

[REQUIRED] Describe the problem

Steps to reproduce:

Running the following code with deno run -A --location http://foo.com test.ts will hang forever after the finish is outputted, even though I'm calling deleteApp.

// test.ts

// @deno-types="https://cdn.esm.sh/v58/[email protected]/app/dist/app/index.d.ts"
import { deleteApp, FirebaseOptions, initializeApp } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-app.js";
// @deno-types="https://cdn.esm.sh/v58/[email protected]/database/dist/database/index.d.ts"
import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/9.6.0/firebase-database.js";

const app = initializeApp({...});
const db = getDatabase(app);
await set(ref(db), 1);
deleteApp(app);
console.log("finish");

I changed it to log the setTimeout call using the following code and found that setTimeout called the reportStats_ method forever.

const originalSetTimeout = globalThis.setTimeout;
globalThis.setTimeout = (...args) => {
  const timeoutId = originalSetTimeout(...args);
  console.log({ timeoutId }, ...args);
  return timeoutId;
};

The reason for this may be that the implementation of setTimeout in Deno is web compatible and there is no unref method.
We probably need to stop using the unref method and call crearTimeout() when deleteApp() is called.

const timeout: number | object = setTimeout(fn, time);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (typeof timeout === 'object' && (timeout as any)['unref']) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(timeout as any)['unref']();
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions