Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 80dcc55

Browse files
committed
feat(nitro-node): trap terminate signal in order to kill nitro process
As nitro process is spawned in daemon mode, the library should be able to trap SIGTERM signal in order to kill nitro process.
1 parent ae1d4dd commit 80dcc55

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

nitro-node/src/nitro.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ export async function checkMagicBytes(
152152
chunks.push(chunk);
153153
}
154154
const actual = Buffer.concat(chunks);
155-
log(`Comparing file's magic bytes <${actual.toString()}> and desired <${desired.toString()}>`);
155+
log(
156+
`Comparing file's magic bytes <${actual.toString()}> and desired <${desired.toString()}>`,
157+
);
156158
return Buffer.compare(actual, desired) === 0;
157159
}
158160

@@ -499,3 +501,11 @@ export async function getResourcesInfo(): Promise<ResourcesInfo> {
499501
export const updateNvidiaInfo = async () =>
500502
await _updateNvidiaInfo(nvidiaConfig);
501503
export const getCurrentNitroProcessInfo = () => getNitroProcessInfo(subprocess);
504+
505+
/**
506+
* Trap for system signal so we can stop nitro process on exit
507+
*/
508+
process.on("SIGTERM", async () => {
509+
log(`[NITRO]::Debug: Received SIGTERM signal`);
510+
await killSubprocess();
511+
});

nitro-node/src/scripts/download-nitro.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const downloadBinaries = (
150150
);
151151
};
152152

153-
// Check for a files with nitro in name in the corresponding directory
153+
// Check for files with nitro in name in the corresponding directory
154154
const verifyDownloadedBinaries = (absBinDirPath: string) => {
155155
// Check all the paths in variantConfig for a file with nitro in its name
156156
return Object.values(variantConfig).every((binDirVariant: string) => {

0 commit comments

Comments
 (0)