Skip to content

Commit

Permalink
fix: unable to kill fuels dev with pnpm (#3508)
Browse files Browse the repository at this point in the history
* chore: changeset

* chore: release to NPM

* chore: changeset

* fix: enabled killing of the underlying process

* chore: updated changeset

* chore: finalise PR

* fix: final issue with listeners causing `fuels dev` failures

* chore: release

* Update .github/workflows/pr-release.yaml

---------

Co-authored-by: Anderson Arboleya <[email protected]>
Co-authored-by: Nedim Salkić <[email protected]>
  • Loading branch information
3 people authored Jan 6, 2025
1 parent 8d8452e commit a278e71
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
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

0 comments on commit a278e71

Please sign in to comment.