Skip to content

Commit

Permalink
fix(core): daemon termination should be ok when client does not need …
Browse files Browse the repository at this point in the history
…anything (#12519)
  • Loading branch information
vsavkin authored Oct 11, 2022
1 parent f37c334 commit 8c393b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/nx/src/daemon/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,19 @@ export class DaemonClient {
});

this.socket.on('close', () => {
output.error({
title: 'Daemon process terminated and closed the connection',
bodyLines: ['Please rerun the command, which will restart the daemon.'],
});
process.exit(1);
// it's ok for the daemon to terminate if the client doesn't wait on
// any messages from the daemon
if (this.queue.isEmpty()) {
this._connected = false;
} else {
output.error({
title: 'Daemon process terminated and closed the connection',
bodyLines: [
'Please rerun the command, which will restart the daemon.',
],
});
process.exit(1);
}
});

this.socket.on('error', (err) => {
Expand Down
10 changes: 10 additions & 0 deletions packages/nx/src/utils/promised-based-queue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export class PromisedBasedQueue {
private counter = 0;
private promise = Promise.resolve(null);

sendToQueue(fn: () => Promise<any>): Promise<any> {
this.counter++;
let res, rej;
const r = new Promise((_res, _rej) => {
res = _res;
Expand All @@ -12,17 +14,25 @@ export class PromisedBasedQueue {
.then(async () => {
try {
res(await fn());
this.counter--;
} catch (e) {
rej(e);
this.counter--;
}
})
.catch(async () => {
try {
res(await fn());
this.counter--;
} catch (e) {
rej(e);
this.counter--;
}
});
return r;
}

isEmpty() {
return this.counter === 0;
}
}

1 comment on commit 8c393b5

@vercel
Copy link

@vercel vercel bot commented on 8c393b5 Oct 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.