nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.84k stars 2.38k forks source link

createProjectGraphAsync prevents program from finishing #20470

Open mpsanchis opened 1 year ago

mpsanchis commented 1 year ago

Current Behavior

The following command doesn't finish in a terminal:

node myscript.js

If myscript is (simplest use case I could create):

const {createProjectGraphAsync} = require("@nx/devkit");

createProjectGraphAsync().then(projects => console.log(`myapp name: ${projects.nodes['myapp'].data.name}`))

Expected Behavior

Code finishes execution and terminal can run other commands after.

GitHub Repo

No response

Steps to Reproduce

  1. Create a simple JS program that imports and uses createProjectGraphAsync
  2. Run it with node

Nx Report

Node   : 18.18.2
   OS     : darwin-arm64
   npm    : 9.8.1

   nx                 : 17.0.2
   @nx/js             : 17.0.2
   @nx/jest           : 17.0.2
   @nx/linter         : 17.0.2
   @nx/eslint         : 17.0.2
   @nx/workspace      : 17.0.2
   @nx/cypress        : 17.0.2
   @nx/devkit         : 17.0.2
   @nx/eslint-plugin  : 17.0.2
   @nx/plugin         : 17.0.2
   @nx/react          : 17.0.2
   @nrwl/tao          : 17.0.2
   @nx/vite           : 17.0.2
   @nx/web            : 17.0.2
   typescript         : 5.1.3
   ---------------------------------------
   Community plugins:
   @jnxplus/nx-maven      : 0.15.1
   @jscutlery/semver      : 3.4.0
   @ngx/deploy-npm        : 7.1.0
   @nx-tools/nx-container : 5.0.2

Failure Logs

No response

Package Manager Version

pnpm 8.10.0

Operating System

Additional Information

Came up in a conversation with Caleb on discord

jbadeau commented 1 year ago

Is this possibly the same issue why nx daemon is disabled in ci? Jobs exit before the daemon exits?

mortargrind commented 7 months ago

Would having an option in the arguments to control Daemon usage without meddling with global project/workspace configuration acceptable?

FrozenPandaz commented 6 months ago

We have this flag. https://nx.dev/nx-api/devkit/documents/createProjectGraphAsync#parameters

It is called resetDaemonClient.

Though I will admit it is a weird name and it isn't well documented.

  1. Would someone like to open a PR to document it better?
  2. Do you have a better name in mind for it?
mpsanchis commented 6 months ago

I wouldn't mind adding some more documentation, but I am not sure I fully understand why the process I spawn gets stuck if the daemon client is not reset. What I understand from the nx docs is that the daemon is a process running in background, and other processes can communicate with it. I would expect that my process does:

  1. Make a request to the daemon
  2. Get the answer and log it
  3. Exit

However I see that the flag is called resetDaemonClient and not resetDaemonServer, which makes me think that createProjectGraphAsync is spawning a client in a separate process, which does not end, and then my main process doesn't end because there is a child of his still alive. Am I correct? If this is correct, I could add this information somewhere, for sure :) I'm understanding Nx more with time, and it'd be a nice first contribution.

github-actions[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it hasn't had any activity for 6 months. Many things may have changed within this time. The issue may have already been fixed or it may not be relevant anymore. If at this point, this is still an issue, please respond with updated information. It will be closed in 21 days if no further activity occurs. Thanks for being a part of the Nx community! 🙏