Skip to content

Commit 9eed361

Browse files
authored
Use FUNCTIONS_DISCOVERY_TIMEOUT when waiting for sockets (#7838)
* Use FUNCTIONS_DISCOVERY_TIMEOUT when waiting for sockets during functions discovery * Type cleanup & maybe fixing tests
1 parent 372d0b1 commit 9eed361

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
- Removed outdated dependency on `rimraf`.
44
- Fixed an issue where the Extensions emulator would fail silently if started with a non-existant project without the `demo-` prefix. (#7779)
55
- 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)
6+
- Fixed an issue during functions discovery where `FUNCTIONS_DISCOVERY_TIMEOUT` wasn't respected. (#6285)
67
- Improved handling when `emulators:export` cannot read the metadata file.

src/deploy/functions/runtimes/discovery/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export const readFileAsync = promisify(fs.readFile);
1515

1616
const TIMEOUT_OVERRIDE_ENV_VAR = "FUNCTIONS_DISCOVERY_TIMEOUT";
1717

18+
export function getFunctionDiscoveryTimeout(): number {
19+
return +(process.env[TIMEOUT_OVERRIDE_ENV_VAR] || 0) * 1000; /* ms */
20+
}
21+
1822
/**
1923
* Converts the YAML retrieved from discovery into a Build object for param interpolation.
2024
*/
@@ -75,14 +79,9 @@ export async function detectFromPort(
7579
): Promise<build.Build> {
7680
let res: Response;
7781
const timedOut = new Promise<never>((resolve, reject) => {
78-
setTimeout(
79-
() => {
80-
reject(
81-
new FirebaseError("User code failed to load. Cannot determine backend specification"),
82-
);
83-
},
84-
+(process.env[TIMEOUT_OVERRIDE_ENV_VAR] || 0) * 1000 /* ms */ || timeout,
85-
);
82+
setTimeout(() => {
83+
reject(new FirebaseError("User code failed to load. Cannot determine backend specification"));
84+
}, getFunctionDiscoveryTimeout() || timeout);
8685
});
8786

8887
while (true) {

src/emulator/functionsRuntimeWorker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { EventEmitter } from "events";
88
import { EmulatorLogger, ExtensionLogInfo } from "./emulatorLogger";
99
import { FirebaseError } from "../error";
1010
import { Serializable } from "child_process";
11+
import { getFunctionDiscoveryTimeout } from "../deploy/functions/runtimes/discovery";
1112

1213
type LogListener = (el: EmulatorLog) => any;
1314

@@ -264,7 +265,7 @@ export class RuntimeWorker {
264265
const timeout = new Promise<never>((resolve, reject) => {
265266
setTimeout(() => {
266267
reject(new FirebaseError("Failed to load function."));
267-
}, 30_000);
268+
}, getFunctionDiscoveryTimeout() || 30_000);
268269
});
269270
while (true) {
270271
try {

0 commit comments

Comments
 (0)