Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ungit crashes with rapid file system modification #1524

Open
campbellcole opened this issue Jul 12, 2022 · 5 comments
Open

ungit crashes with rapid file system modification #1524

campbellcole opened this issue Jul 12, 2022 · 5 comments

Comments

@campbellcole
Copy link

(This problem has only come up for me with Rust projects, due to the nature of the build procedure)

To reproduce easily:

  • create an empty Cargo project: cargo new ungit_poc
  • in a new shell, run ungit in that folder: cd ungit_poc && ungit
  • in the first shell, run cargo: cargo check or cargo build

Ungit crashes with an error similar to:

Error: ENOENT: no such file or directory, watch '<project_dir>/target/debug/deps/rmetaY6KMh5'

This happens because the target directory is extremely volatile during compilation/checking, and ungit doesn't seem to be written in such a way that handles extremely rapid filesystem mutation.

There are two ways to fix this:

  1. Ensure Ungit does not attempt to watch files in .gitignore/.ignore
  2. Change how FSWatcher is being used so that rapid changes won't cause this race condition
@wmertens
Copy link
Contributor

wmertens commented Jul 13, 2022

Nodegit uses node-watch which does filter ignored dirs, so either that isn't working or you have an old version?

The race itself is interesting, why would it stat the file? Maybe it's a bug in node-watcher, trying to determine what the change is?

A full stack dump would be useful. Also, try to repro in bash with touch and rm.

@campersau
Copy link
Collaborator

Would be nice to get a stacktrace for this. Might be related to yuanchuan/node-watch#108

@campbellcole
Copy link
Author

Ungit version 1.5.20+9ced7530

Stacktrace:

2022-07-14T00:03:15.220Z - error: Error: ENOENT: no such file or directory, watch '/home/campbell/Programming/[removed]/target/debug/deps/rmetawQil0f'
    at FSWatcher.<computed> (node:internal/fs/watchers:244:19)
    at Object.watch (node:fs:2264:34)
    at /home/campbell/.nvm/versions/node/v16.15.1/lib/node_modules/ungit/node_modules/node-watch/lib/watch.js:398:22
    at hasNativeRecursive (/home/campbell/.nvm/versions/node/v16.15.1/lib/node_modules/ungit/node_modules/node-watch/lib/has-native-recursive.js:61:12)
    at Watcher.watchDirectory (/home/campbell/.nvm/versions/node/v16.15.1/lib/node_modules/ungit/node_modules/node-watch/lib/watch.js:381:3)
    at /home/campbell/.nvm/versions/node/v16.15.1/lib/node_modules/ungit/node_modules/node-watch/lib/watch.js:305:20
    at hasNativeRecursive (/home/campbell/.nvm/versions/node/v16.15.1/lib/node_modules/ungit/node_modules/node-watch/lib/has-native-recursive.js:61:12)
    at FSWatcher.internalOnChange (/home/campbell/.nvm/versions/node/v16.15.1/lib/node_modules/ungit/node_modules/node-watch/lib/watch.js:291:7)
    at FSWatcher.emit (node:events:527:28)
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:212:12)
Stopped keeping ungit alive

Can't seem to reproduce this using touch and rm (or mkdir and rm -rf), I think cargo just works too much faster than those commands. The presence of onchange makes me think that the file is created and destroyed before FSWatcher has finished its initial stat of the file.

@wmertens
Copy link
Contributor

right, this seems like a bug with node-watch, where it tries to watch newly created folders but they're already removed by the time it gets to it.

Mostl likely the bug is here https://github.com/yuanchuan/node-watch/blob/5743e51a861bfe3d372a99dd388626b324905065/lib/watch.js#L302-L317

@campbellcole would you mind opening an issue on node-watch?

@campbellcole
Copy link
Author

@wmertens will do. Thanks for your time 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants