paulmillr / chokidar

Minimal and efficient cross-platform file watching library
https://paulmillr.com
MIT License
10.8k stars 574 forks source link

Received an unknown event from `fsevents` then watcher fired `unlink` event for the directory recursively #1286

Closed Singloo closed 1 year ago

Singloo commented 1 year ago

Describe the bug

I'm using vite in work dir WORKDIR, but everytime after running vite for a while, chokidar will fire unlink events to all files under WORKDIR recursively.

I debugged a little, I found that the root cause is an unknown event from fsevents. Here is the data of the event

{
  path: `${WORKDIR}`,
  flags: 3,
  event: "unknown",
  type: undefined,
  changes: {
    inode: false,
    finder: false,
    access: false,
    xattrs: false,
  },
}

Then this line of code will be triggered

Versions (please complete the following information):

To Reproduce:

I cannot reproduce this issue on other project

Expected behavior Provide a way to ignore some unknown events.

Additional context I have watchman, pm2 running on my device

segevfiner commented 1 year ago

Hitting this as well, and it likely causes this two: https://github.com/storybookjs/storybook/issues/22253 https://github.com/vitejs/vite/issues/14126. Though for me it gets triggered from this line https://github.com/paulmillr/chokidar/blob/08318d62f1fa731122d2b8853400f1b3252db8c9/lib/fsevents-handler.js#L249 and a similar kind of unknown event.

segevfiner commented 1 year ago

This event basically means that chokidar or its user isn't processing events fast enough, and as such, must rescan the directory recursively for changes by itself as the FSEvents API dropped/coalesced those events. But for some reason type seems to be unset for this event which confuses chokidar. There seems to be a fix for this in fsevents already: https://github.com/fsevents/fsevents/commit/63709df0fd91549050e2e3f38b1695f49f6387a8, but it wasn't released. You can use patch-package/pnpm patch or so on to apply the fix locally or override to get fsevents from Git.

https://developer.apple.com/documentation/coreservices/kfseventstreameventflagmustscansubdirs https://developer.apple.com/documentation/coreservices/kfseventstreameventflaguserdropped

Singloo commented 1 year ago

This event basically means that chokidar or its user isn't processing events fast enough, and as such, must rescan the directory recursively for changes by itself as the FSEvents API dropped/coalesced those events. But for some reason type seems to be unset for this event which confuses chokidar. There seems to be a fix for this in fsevents already: fsevents/fsevents@63709df, but it wasn't released.

https://developer.apple.com/documentation/coreservices/kfseventstreameventflagmustscansubdirs https://developer.apple.com/documentation/coreservices/kfseventstreameventflaguserdropped

It works, many thanks

segevfiner commented 1 year ago

@paulmillr Making a release of fsevents will solve this.

IanVS commented 1 year ago

Hi @paulmillr, this is effecting a fairly large number of Vite and Storybook users. Do you think it would be possible to cut a release of fsevents in the near future?

Thanks @Singloo and @segevfiner for troubleshooting and finding the cause!

paulmillr commented 1 year ago

@pipobscure what's needed to publish this? Seems like GitHub publish workflow is failing. Not sure where to begin.

pipobscure commented 1 year ago

Released as v2.3.3