nx icon indicating copy to clipboard operation
nx copied to clipboard

Nx watch goes into indefinite loop

Open ThePlenkov opened this issue 10 months ago • 4 comments

Current Behavior

Hi! I think I just managed to reproduce a situation when nx watch goes into an indefinite loop constantly running same task again and again. It runs build command which is supposed to be cached ( and it is ) but DaemonSocketMessenger keeps receiving the information that file is changed and runs same command again.

Expected Behavior

It's ok if watch command listens for all files ( ideally I would prefer that watch can also accept somehow only certain files to watch, not for everything ) but even though it should not run the command again if file was processed ( target inputs are not changed and target result is cached )

GitHub Repo

https://github.com/ThePlenkov/nx-plantuml

Steps to Reproduce

Preferably open repo in codespaces or make sure you have docker installed ( for command execution )

  1. npm run dev
  2. Make any change, like for example add a new line to readme

Nx Report

Node   : 20.12.1
OS     : linux-x64
npm    : 10.5.0

nx         : 18.3.1
@nrwl/tao  : 18.3.1

Failure Logs

No response

Package Manager Version

No response

Operating System

  • [ ] macOS
  • [X] Linux
  • [ ] Windows
  • [ ] Other (Please specify)

Additional Information

No response

ThePlenkov avatar Apr 19 '24 16:04 ThePlenkov

I tried to disable daemon - it stays same

ThePlenkov avatar Apr 19 '24 16:04 ThePlenkov

tried to use nx:run-commands executor instead of npm script - same result..

ThePlenkov avatar Apr 19 '24 16:04 ThePlenkov

Did you try to add

"nx": { "includedScripts": [] }

to package json

jbadeau avatar May 03 '24 03:05 jbadeau

On vacation now - will check when come. But from another side I don't want to ignore scripts, I think what happens - is that watch doesn't analyze inputs and outputs properly running task even if it's cached

ThePlenkov avatar May 04 '24 03:05 ThePlenkov

Hey! Is this still happening to you on the latest version of nx @ThePlenkov? I fixed an issue a while back where the daemon would sometimes pick up changes inside the .nx folder or something like that and it was causing loops in Nx Console as well. Could you please confirm that it still happens for you? In that case I will try and track it down.

MaxKless avatar Jul 26 '24 13:07 MaxKless

@MaxKless I tried but I cannot run 'nx watch` anymore. I have this

npm run dev

> [email protected] dev
> nx watch --all -- npx nx build \$NX_PROJECT_NAME


 NX   Daemon is not running. The watch command is not supported without the Nx Daemon.

and even if I do this - it doesn't help:

npx nx daemon --start

 NX   Daemon Server - Started in a background process...

Logs from the Daemon process (ID: 6672) can be found here: /workspaces/nx-plantuml/.nx/workspace-data/d/daemon.log

ThePlenkov avatar Aug 01 '24 10:08 ThePlenkov

here is a similar issue: https://github.com/lerna/lerna/issues/4054

ThePlenkov avatar Aug 01 '24 10:08 ThePlenkov

I also see that daemon is actually running:

 npx nx daemon 
Nx Daemon is currently running:
  - Logs: /workspaces/nx-plantuml/.nx/workspace-data/d/daemon.log
  - Process ID: 6672
@ThePlenkov ➜ /workspaces/nx-plantuml (main) $ npm run dev

> [email protected] dev
> nx watch --all -- npx nx build \$NX_PROJECT_NAME


 NX   Daemon is not running. The watch command is not supported without the Nx Daemon.

ThePlenkov avatar Aug 01 '24 10:08 ThePlenkov

and here is the log:

[NX Daemon Server] - 2024-08-01T10:14:32.596Z - Started listening on: /tmp/3cb767b5e4c3571b057f/d.sock
[NX Daemon Server] - 2024-08-01T10:14:32.598Z - [WATCHER]: Subscribed to changes within: /workspaces/nx-plantuml (native)
[NX Daemon Server] - 2024-08-01T10:14:32.603Z - Established a connection. Number of open connections: 1
[NX Daemon Server] - 2024-08-01T10:14:32.605Z - Closed a connection. Number of open connections: 0
[NX Daemon Server] - 2024-08-01T10:21:02.298Z - Established a connection. Number of open connections: 1
[NX Daemon Server] - 2024-08-01T10:21:02.300Z - Closed a connection. Number of open connections: 0

ThePlenkov avatar Aug 01 '24 10:08 ThePlenkov

you can reproduce yourself - just by running npm run dev in a codespace for this project https://github.com/ThePlenkov/nx-plantuml

ThePlenkov avatar Aug 01 '24 10:08 ThePlenkov

This issue has been automatically marked as stale because no results of retrying on the latest version of Nx was provided within 7 days. It will be closed in 21 days if no results are provided. If the issue is still present, please reply to keep it active. If the issue was not present, please close this issue. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar Aug 09 '24 00:08 github-actions[bot]