Skip to content

Commit

Permalink
fix: capture exit event if the process is killed
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Oct 3, 2022
1 parent 39e35c8 commit a39a0f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-mugs-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"phpstan-vscode": patch
---

Fix memory leak when the process is killed
3 changes: 3 additions & 0 deletions src/utils/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export async function killProcess(p: ChildProcess) {
export async function waitForClose(childProcess: ChildProcess) {
return new Promise<number | null>((resolve, reject) => {
childProcess.on("error", reject);
childProcess.on("exit", (exitCode) => {
if (childProcess.killed) resolve(exitCode);
});
childProcess.on("close", (exitCode) => resolve(exitCode));
});
}

0 comments on commit a39a0f4

Please sign in to comment.