haskell-fswatch / hfsnotify

Unified Haskell interface for basic file system notifications
BSD 3-Clause "New" or "Revised" License
136 stars 40 forks source link

`watchDir` misses some Git events, `watchTree` shows them all on Linux #97

Open mgajda opened 3 years ago

mgajda commented 3 years ago

I have been playing with a minimal script to show all events on the directory tree:

{-# LANGUAGE ScopedTypeVariables #-}
module Main where

import Control.Monad(forever)
import Control.Concurrent
import Control.Concurrent.Chan as Chan
import System.FSNotify

main = do
  evtChan <- Chan.newChan
  forkIO $ forever $ readChan evtChan >>= print
  withManagerConf (defaultConfig { confDebounce = NoDebounce
                                 , confUsePolling = False }) $ \mgr -> do
    System.FSNotify.watchDirChan mgr "." (const True) evtChan
    threadDelay 10000000000

This script misses some of the file changes when executing git checkout HEAD~1 on a repo with multiple files changed per patch.

The same thing happens for watchDir and watchDirChan, but replacing with watchTree or watchTreeChan fixes the issue.

This issue caused another in enTangled.

thomasjm commented 3 years ago

Not sure I understand -- watchDir/watchDirChan are the non-recursive versions, so it's expected that they'll miss events in subdirectories, if that's what's happening.

Can you provide a complete repro showing the problem?

mgajda commented 3 years ago

These are events in the same directory, not subdirectories.

mgajda commented 3 years ago

Complete repro is in entangled repo: https://github.com/entangled/entangled/pull/80#issuecomment-712861195 Since similar issue seems to occur with confPolling = True on Ubuntu 20.04, I will investigate more carefully, and hopefully then we can copy complete repro script here.

thomasjm commented 3 years ago

Okay, I'll wait for the repro script to look deeply into this.

As many details as you could provide would be helpful, such as the event types and order of events that causes the problem.

You might also want to make sure confUsePolling = False, since polling can definitely miss events--for example, if a file is quickly created and then deleted in between polls. (There seems to be some confusion about whether polling is enabled in the linked discussion.)

mgajda commented 3 years ago

@thomasjm Our test only aims for eventual consistency, so it is the situation where file is changed and not reported at all that seems most concerning.

thomasjm commented 3 years ago

@mgajda sounds good -- I'm ready to look at a simple repro script anytime.