cozy-labs / cozy-desktop

File Synchronisation for Cozy on Desktop and Laptop
https://cozy-labs.github.io/cozy-desktop/
GNU Affero General Public License v3.0
99 stars 45 forks source link

fix: Process Chokidar events batches sequentially #2324

Closed taratatach closed 12 months ago

taratatach commented 1 year ago

We buffer events emitted by Chokidar as the underlying FSEvents API, on macOS, can add delay between events relating to the same document and processing the first events without the latter ones can lead to wrong assumptions about what changes were actually made.

Buffered events are then flushed 10 seconds after the last event was buffered (i.e. each buffered event resets the 10 seconds delay).

Since this process is asynchronous and is only time-based, we can end up flushing buffered events while some previous batch is still being processed, creating situations where unexpected behavior can happen.

To prevent this, we now prevent any buffer flushes while a batch is being processed and restore the flushing timeout once finished. This can add a small delay to the next batch processing but since we don't know if already buffered events could be flushed at that point it seems safer.

Please make sure the following boxes are checked:

taratatach commented 12 months ago

Closing in favor of #2325.