Skip to content
Open
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
18 changes: 11 additions & 7 deletions src/deploy/functions/runtimes/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
throw new FirebaseError(`Unexpected runtime ${runtime}`);
}

return new Delegate(context.projectId, context.projectDir, context.sourceDir, runtime);

Check warning on line 60 in src/deploy/functions/runtimes/node/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'Delegate' was used before it was defined
}

// TODO(inlined): Consider moving contents in parseRuntimeAndValidateSDK and validate around.
Expand Down Expand Up @@ -265,24 +265,28 @@
): Promise<() => Promise<void>> {
const childProcess = this.spawnFunctionsProcess(config, { ...envs, PORT: port });

const pExit = new Promise<void>((resolve, reject) => {
childProcess.once("exit", resolve);
childProcess.once("error", reject);
});

// TODO: Refactor return type to () => Promise<void> to simplify nested promises
return Promise.resolve(async () => {
const p = new Promise<void>((resolve, reject) => {
childProcess.once("exit", resolve);
childProcess.once("error", reject);
});

try {
await fetch(`http://localhost:${port}/__/quitquitquit`);
} catch (e) {
logger.debug("Failed to call quitquitquit. This often means the server failed to start", e);
}
setTimeout(() => {

const quitTimeout = setTimeout(() => {
if (!childProcess.killed) {
childProcess.kill("SIGKILL");
}
}, 10_000);
return p;

return pExit.finally(() => {
clearTimeout(quitTimeout);
});
});
}

Expand Down
14 changes: 10 additions & 4 deletions src/deploy/functions/runtimes/python/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{ exit: 1 },
);
}
return Promise.resolve(new Delegate(context.projectId, context.sourceDir, runtime));

Check warning on line 42 in src/deploy/functions/runtimes/python/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

'Delegate' was used before it was defined
}

/**
Expand Down Expand Up @@ -148,7 +148,7 @@
return Promise.resolve();
}

async serveAdmin(port: number, envs: backend.EnvironmentVariables) {

Check warning on line 151 in src/deploy/functions/runtimes/python/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function
const modulesDir = await this.modulesDir();
const envWithAdminPort = {
...envs,
Expand All @@ -167,21 +167,27 @@
childProcess.stderr?.on("data", (chunk: Buffer) => {
logger.error(chunk.toString("utf8"));
});

const pExit = new Promise<void>((resolve, reject) => {
childProcess.once("exit", resolve);
childProcess.once("error", reject);
});

return Promise.resolve(async () => {
try {
await fetch(`http://127.0.0.1:${port}/__/quitquitquit`);
} catch (e) {
logger.debug("Failed to call quitquitquit. This often means the server failed to start", e);
}

const quitTimeout = setTimeout(() => {
if (!childProcess.killed) {
childProcess.kill("SIGKILL");
}
}, 10_000);
clearTimeout(quitTimeout);
return new Promise<void>((resolve, reject) => {
childProcess.once("exit", resolve);
childProcess.once("error", reject);

return pExit.finally(() => {
clearTimeout(quitTimeout);
});
});
Comment on lines 176 to 192
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since serveAdmin is an async function, it already returns a Promise. You can remove the explicit Promise.resolve wrapper for simplicity.

Suggested change
return Promise.resolve(async () => {
try {
await fetch(`http://127.0.0.1:${port}/__/quitquitquit`);
} catch (e) {
logger.debug("Failed to call quitquitquit. This often means the server failed to start", e);
}
const quitTimeout = setTimeout(() => {
if (!childProcess.killed) {
childProcess.kill("SIGKILL");
}
}, 10_000);
clearTimeout(quitTimeout);
return new Promise<void>((resolve, reject) => {
childProcess.once("exit", resolve);
childProcess.once("error", reject);
return pExit.finally(() => {
clearTimeout(quitTimeout);
});
});
return async () => {
try {
await fetch(`http://127.0.0.1:${port}/__/quitquitquit`);
} catch (e) {
logger.debug("Failed to call quitquitquit. This often means the server failed to start", e);
}
const quitTimeout = setTimeout(() => {
if (!childProcess.killed) {
childProcess.kill("SIGKILL");
}
}, 10_000);
return pExit.finally(() => {
clearTimeout(quitTimeout);
});
};

}
Expand Down
Loading