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

fix: unable to kill fuels dev with pnpm #3508

Merged
merged 12 commits into from
Jan 6, 2025
6 changes: 6 additions & 0 deletions .changeset/thin-planes-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/account": patch
"fuels": patch
---

fix: unable to kill `fuels dev` with `pnpm`
26 changes: 20 additions & 6 deletions packages/account/src/test-utils/launchNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type LaunchNodeOptions = {
* */
snapshotConfig?: SnapshotConfigs;
includeInitialState?: boolean;
killProcessOnExit?: boolean;
};

export type LaunchNodeResult = Promise<{
Expand Down Expand Up @@ -143,6 +144,7 @@ export const launchNode = async ({
basePath,
snapshotConfig = defaultSnapshotConfigs,
includeInitialState = false,
killProcessOnExit = false,
}: LaunchNodeOptions = {}): LaunchNodeResult =>
// eslint-disable-next-line no-async-promise-executor
new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -241,16 +243,15 @@ export const launchNode = async ({
});
}

const removeSideffects = () => {
const removeChildListeners = () => {
child.stderr.removeAllListeners();
};
const removeTempDir = () => {
if (existsSync(tempDir)) {
rmSync(tempDir, { recursive: true });
}
};

child.on('error', removeSideffects);
child.on('exit', removeSideffects);

const childState = {
isDead: false,
};
Expand All @@ -261,7 +262,8 @@ export const launchNode = async ({
}
childState.isDead = true;

removeSideffects();
removeChildListeners();

if (child.pid !== undefined) {
try {
process.kill(-child.pid);
Expand All @@ -284,6 +286,7 @@ export const launchNode = async ({
// eslint-disable-next-line no-console
console.error('No PID available for the child process, unable to kill launched node');
}
removeTempDir();
};

// Look for a specific graphql start point in the output.
Expand Down Expand Up @@ -331,5 +334,16 @@ export const launchNode = async ({
process.on('beforeExit', cleanup);
process.on('uncaughtException', cleanup);

child.on('error', reject);
child.on('exit', (code: number | null, _signal: NodeJS.Signals | null) => {
removeChildListeners();
removeTempDir();
if (killProcessOnExit) {
process.exit(code);
}
});
child.on('error', (err: Error) => {
removeChildListeners();
removeTempDir();
reject(err);
});
});
1 change: 1 addition & 0 deletions packages/fuels/src/cli/commands/dev/autoStartFuelCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const autoStartFuelCore = async (config: FuelsConfig) => {
basePath: config.basePath,
fuelCorePath: config.fuelCorePath,
includeInitialState: true,
killProcessOnExit: true,
});

fuelCore = {
Expand Down
Loading