Skip to content

Commit 744cb3a

Browse files
fix(core): commands shouldn't hang when passing --help (#34506)
## Current Behavior `--help` on commands that hit yargs help are hanging ## Expected Behavior It doesn't hang. This contains a quick fix in adding the process.exit call, but also adds the unref needed to maintain previous working behavior. We'll need to investigate long term if additional areas keep commands alive, but adding this unref theoretically allows removing the process.exit calls from `nx show` ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # --------- Co-authored-by: Jason Jean <jasonjean1993@gmail.com> (cherry picked from commit df8a2c4)
1 parent 4bb6006 commit 744cb3a

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

packages/nx/bin/init-local.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export async function initLocal(workspace: WorkspaceTypeAndRoot) {
4747
const split = newArgs.indexOf('--');
4848
if (help > -1 && (split === -1 || split > help)) {
4949
commandsObject.showHelp();
50+
process.exit(0);
5051
} else {
5152
commandsObject.parse(newArgs);
5253
}

packages/nx/src/daemon/client/client.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,9 +1038,12 @@ export class DaemonClient {
10381038
private setUpConnection() {
10391039
const socketPath = this.getSocketPath();
10401040

1041-
this.socketMessenger = new DaemonSocketMessenger(
1042-
connect(socketPath)
1043-
).listen(
1041+
const socket = connect(socketPath);
1042+
// Unref the socket so it doesn't keep the process alive. The
1043+
// sendMessageToDaemon method uses a keep-alive setTimeout to
1044+
// explicitly hold the event loop open while awaiting a response.
1045+
socket.unref();
1046+
this.socketMessenger = new DaemonSocketMessenger(socket).listen(
10441047
(message) => this.handleMessage(message),
10451048
() => {
10461049
// it's ok for the daemon to terminate if the client doesn't wait on

0 commit comments

Comments
 (0)