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

Watch mode should wait for file write. (T7411) #3698

Merged
merged 1 commit into from Jan 15, 2017

Conversation

hayeah
Copy link
Contributor

@hayeah hayeah commented Sep 3, 2016

https://phabricator.babeljs.io/T7411#81534

The problem is that some editors (e.g. VScode) saves by truncating the file then writing. There's a race condition where

  1. Editor truncates the file.
  2. File system sends change event, and Babel compiles the empty file
  3. Editor writes the file.

I am only seeing this problem happening with the combination of VSCode and Linux.

Fixing this problem would require adding awaitWriteFinish to chokidar's watch command.

Not sure what default would work well for everybody. I am using 50ms stability threshold and 10ms polling intervals, which seems to behave well in my case.

@codecov-io
Copy link

codecov-io commented Sep 3, 2016

Current coverage is 88.32% (diff: 100%)

Merging #3698 into master will not change coverage

@@             master      #3698   diff @@
==========================================
  Files           194        194          
  Lines         13611      13611          
  Methods        1427       1427          
  Messages          0          0          
  Branches       3142       3142          
==========================================
  Hits          12022      12022          
  Misses         1589       1589          
  Partials          0          0          

Powered by Codecov. Last update 8f790ce...32232dd

@arcanis
Copy link
Contributor

arcanis commented Sep 5, 2016

There's an other PR related to this issue here: #3682.

However, even with this change applied, I still noticed some fails, and eventually moved to a manual make/inotify-based watch system.

@@ -71,7 +71,11 @@ module.exports = function (commander, filenames) {
_.each(filenames, function (dirname) {
let watcher = chokidar.watch(dirname, {
persistent: true,
ignoreInitial: true
ignoreInitial: true,
awaitWriteFinish: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was added in Chokidar 1.2 and our deps are currently ^1.0.0, can we bump that up to the current version ^1.6.0?

ignoreInitial: true,
awaitWriteFinish: {
stabilityThreshold: 50,
pollInterval: 10,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a pretty fast interval, perhaps we should do more like 200 and 50?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

200 is too close to perception threshold, IMO.

This is not continual poll, and is only active when change event occurs. Performance wise is probably not a big deal.

Works well for me, YMMV.

@sebdeckers
Copy link
Contributor

Anything blocking the merge of this patch? Seems the other PR was closed in favour of this one.

The race condition is especially evident on machines with high latency storage (non-SSD). Noticing this about 50% of the time when saving files to HDD with vscode.

/cc @teochengyong

@loganfsmyth loganfsmyth merged commit 40746f3 into babel:master Jan 15, 2017
@hzoo hzoo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Jan 19, 2017
@hzoo
Copy link
Member

hzoo commented Jan 20, 2017

Released in https://github.com/babel/babel/releases/tag/v6.22.0

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants