-
Notifications
You must be signed in to change notification settings - Fork 987
Closed
Labels
Description
[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.
firebase-js-sdk/packages/database/src/core/util/util.ts
Lines 620 to 625 in cdada6c
| 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'](); | |
| } |