Skip to content

Commit

Permalink
fix(core): misc daemon fixes (#15472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Mar 20, 2023
1 parent 61fb737 commit 84075c3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/nx/src/command-line/migrate.ts
Expand Up @@ -56,6 +56,7 @@ import { isCI } from '../utils/is-ci';
import { getNxRequirePaths } from '../utils/installation-directory';
import { readNxJson } from '../config/configuration';
import { runNxSync } from '../utils/child-process';
import { daemonClient } from '../daemon/client/client';

export interface ResolvedMigrationConfiguration extends MigrationsJson {
packageGroup?: ArrayPackageGroup;
Expand Down Expand Up @@ -1553,6 +1554,8 @@ export async function migrate(
process.env.NX_VERBOSE_LOGGING = 'true';
}

await daemonClient.stop();

return handleErrors(process.env.NX_VERBOSE_LOGGING === 'true', async () => {
const opts = await parseMigrationsOptions(args);
if (opts.type === 'generateMigrations') {
Expand Down
17 changes: 14 additions & 3 deletions packages/nx/src/daemon/client/client.ts
@@ -1,6 +1,7 @@
import { workspaceRoot } from '../../utils/workspace-root';
import { ChildProcess, spawn } from 'child_process';
import { openSync, readFileSync, statSync } from 'fs';
import { FileHandle, open } from 'fs/promises';
import { ensureDirSync, ensureFileSync } from 'fs-extra';
import { connect } from 'net';
import { join } from 'path';
Expand Down Expand Up @@ -48,6 +49,8 @@ export class DaemonClient {

private _enabled: boolean | undefined;
private _connected: boolean;
private _out: FileHandle = null;
private _err: FileHandle = null;

enabled() {
if (this._enabled === undefined) {
Expand Down Expand Up @@ -86,12 +89,19 @@ export class DaemonClient {
}

reset() {
this.socketMessenger?.close();
this.socketMessenger = null;
this.queue = new PromisedBasedQueue();
this.currentMessage = null;
this.currentResolve = null;
this.currentReject = null;
this._enabled = undefined;

this._out?.close();
this._err?.close();
this._out = null;
this._err = null;

this._connected = false;
}

Expand Down Expand Up @@ -312,14 +322,15 @@ export class DaemonClient {
ensureDirSync(DAEMON_DIR_FOR_CURRENT_WORKSPACE);
ensureFileSync(DAEMON_OUTPUT_LOG_FILE);

const out = openSync(DAEMON_OUTPUT_LOG_FILE, 'a');
const err = openSync(DAEMON_OUTPUT_LOG_FILE, 'a');
this._out = await open(DAEMON_OUTPUT_LOG_FILE, 'a');
this._err = await open(DAEMON_OUTPUT_LOG_FILE, 'a');

const backgroundProcess = spawn(
process.execPath,
[join(__dirname, '../server/start.js')],
{
cwd: workspaceRoot,
stdio: ['ignore', out, err],
stdio: ['ignore', this._out.fd, this._err.fd],
detached: true,
windowsHide: true,
shell: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/daemon/tmp-dir.ts
Expand Up @@ -50,7 +50,7 @@ export function isDaemonDisabled() {

function socketDirName() {
const hasher = createHash('sha256');
hasher.update(workspaceRoot);
hasher.update(workspaceRoot.toLowerCase());
const unique = hasher.digest('hex').substring(0, 20);
return join(tmpdir, unique);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/nx/src/project-graph/project-graph.ts
Expand Up @@ -130,10 +130,11 @@ export async function createProjectGraphAsync(
}
} else {
try {
const projectGraph = await daemonClient.getProjectGraph();
if (opts.resetDaemonClient) {
daemonClient.reset();
}
return await daemonClient.getProjectGraph();
return projectGraph;
} catch (e) {
if (e.message.indexOf('inotify_add_watch') > -1) {
// common errors with the daemon due to OS settings (cannot watch all the files available)
Expand Down

1 comment on commit 84075c3

@vercel
Copy link

@vercel vercel bot commented on 84075c3 Mar 20, 2023

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-git-master-nrwl.vercel.app
nx-five.vercel.app
nx.dev
nx-dev-nrwl.vercel.app

Please sign in to comment.