Skip to content

Commit

Permalink
fix closing an already closed process
Browse files Browse the repository at this point in the history
  • Loading branch information
ebebbington committed May 4, 2024
1 parent e6f7db9 commit c9d0b1d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class Client {
*/
readonly #browser_process: Deno.ChildProcess;

#closed = false;

/**
* The host and port that the websocket server is listening on
*/
Expand Down Expand Up @@ -68,6 +70,10 @@ export class Client {
errMsg?: string,
errClass: { new (message: string): Error } = Error,
) {
if (this.#closed) {
return;
}

// Close browser process (also closes the ws endpoint, which in turn closes all sockets)
const p = deferred();
this.#socket.onclose = () => p.resolve();
Expand All @@ -76,6 +82,7 @@ export class Client {
this.#browser_process.kill();
await this.#browser_process.status;
await p;
this.#closed = true;

if (errMsg) {
throw new errClass(errMsg);
Expand Down

0 comments on commit c9d0b1d

Please sign in to comment.