Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FUNCTIONS_DISCOVERY_TIMEOUT when waiting for sockets #7838

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
15 changes: 7 additions & 8 deletions src/deploy/functions/runtimes/discovery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,30 @@

const TIMEOUT_OVERRIDE_ENV_VAR = "FUNCTIONS_DISCOVERY_TIMEOUT";

export function getFunctionDiscoveryTimeout(): number {

Check warning on line 18 in src/deploy/functions/runtimes/discovery/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
return +(process.env[TIMEOUT_OVERRIDE_ENV_VAR] || 0) * 1000; /* ms */
}

/**
* Converts the YAML retrieved from discovery into a Build object for param interpolation.
*/
export function yamlToBuild(
yaml: any,

Check warning on line 26 in src/deploy/functions/runtimes/discovery/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
project: string,
region: string,
runtime: Runtime,
): build.Build {
try {
if (!yaml.specVersion) {

Check warning on line 32 in src/deploy/functions/runtimes/discovery/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .specVersion on an `any` value
throw new FirebaseError("Expect manifest yaml to specify a version number");
}
if (yaml.specVersion === "v1alpha1") {

Check warning on line 35 in src/deploy/functions/runtimes/discovery/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .specVersion on an `any` value
return v1alpha1.buildFromV1Alpha1(yaml, project, region, runtime);
}
throw new FirebaseError(
"It seems you are using a newer SDK than this version of the CLI can handle. Please update your CLI with `npm install -g firebase-tools`",
);
} catch (err: any) {

Check warning on line 41 in src/deploy/functions/runtimes/discovery/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
throw new FirebaseError("Failed to parse build specification", { children: [err] });
}
}
Expand All @@ -49,9 +53,9 @@
): Promise<build.Build | undefined> {
let text: string;
try {
text = await exports.readFileAsync(path.join(directory, "functions.yaml"), "utf8");

Check warning on line 56 in src/deploy/functions/runtimes/discovery/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 56 in src/deploy/functions/runtimes/discovery/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .readFileAsync on an `any` value

Check warning on line 56 in src/deploy/functions/runtimes/discovery/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value
} catch (err: any) {

Check warning on line 57 in src/deploy/functions/runtimes/discovery/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
if (err.code === "ENOENT") {

Check warning on line 58 in src/deploy/functions/runtimes/discovery/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .code on an `any` value
logger.debug("Could not find functions.yaml. Must use http discovery");
} else {
logger.debug("Unexpected error looking for functions.yaml file:", err);
Expand All @@ -75,14 +79,9 @@
): Promise<build.Build> {
let res: Response;
const timedOut = new Promise<never>((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) {
Expand Down
3 changes: 2 additions & 1 deletion src/emulator/functionsRuntimeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -264,7 +265,7 @@ export class RuntimeWorker {
const timeout = new Promise<never>((resolve, reject) => {
setTimeout(() => {
reject(new FirebaseError("Failed to load function."));
}, 30_000);
}, getFunctionDiscoveryTimeout() || 30_000);
});
while (true) {
try {
Expand Down
Loading