diff --git a/CHANGELOG.md b/CHANGELOG.md index bf1ad7e8008..07c9de9133a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,4 +3,5 @@ - Removed outdated dependency on `rimraf`. - Fixed an issue where the Extensions emulator would fail silently if started with a non-existant project without the `demo-` prefix. (#7779) - Bumped the Firebase Data Connect local toolkit version to v1.5.1, which adds compatible mode schema migration support to the emulator and fixes an issue with the Timestamp type in Swift codegen. (#7837) +- Fixed an issue during functions discovery where `FUNCTIONS_DISCOVERY_TIMEOUT` wasn't respected. (#6285) - Improved handling when `emulators:export` cannot read the metadata file. diff --git a/src/deploy/functions/runtimes/discovery/index.ts b/src/deploy/functions/runtimes/discovery/index.ts index c2489a285dc..cc80b9889ed 100644 --- a/src/deploy/functions/runtimes/discovery/index.ts +++ b/src/deploy/functions/runtimes/discovery/index.ts @@ -15,6 +15,10 @@ export const readFileAsync = promisify(fs.readFile); const TIMEOUT_OVERRIDE_ENV_VAR = "FUNCTIONS_DISCOVERY_TIMEOUT"; +export function getFunctionDiscoveryTimeout(): number { + return +(process.env[TIMEOUT_OVERRIDE_ENV_VAR] || 0) * 1000; /* ms */ +} + /** * Converts the YAML retrieved from discovery into a Build object for param interpolation. */ @@ -75,14 +79,9 @@ export async function detectFromPort( ): Promise { let res: Response; const timedOut = new Promise((resolve, reject) => { - setTimeout( - () => { - reject( - new FirebaseError("User code failed to load. Cannot determine backend specification"), - ); - }, - +(process.env[TIMEOUT_OVERRIDE_ENV_VAR] || 0) * 1000 /* ms */ || timeout, - ); + setTimeout(() => { + reject(new FirebaseError("User code failed to load. Cannot determine backend specification")); + }, getFunctionDiscoveryTimeout() || timeout); }); while (true) { diff --git a/src/emulator/functionsRuntimeWorker.ts b/src/emulator/functionsRuntimeWorker.ts index d8b30bf8e87..5c32326f296 100644 --- a/src/emulator/functionsRuntimeWorker.ts +++ b/src/emulator/functionsRuntimeWorker.ts @@ -8,6 +8,7 @@ import { EventEmitter } from "events"; import { EmulatorLogger, ExtensionLogInfo } from "./emulatorLogger"; import { FirebaseError } from "../error"; import { Serializable } from "child_process"; +import { getFunctionDiscoveryTimeout } from "../deploy/functions/runtimes/discovery"; type LogListener = (el: EmulatorLog) => any; @@ -264,7 +265,7 @@ export class RuntimeWorker { const timeout = new Promise((resolve, reject) => { setTimeout(() => { reject(new FirebaseError("Failed to load function.")); - }, 30_000); + }, getFunctionDiscoveryTimeout() || 30_000); }); while (true) { try {