fsmonitor--daemon: use a cookie file to sync with file system
commitb05880d357c6dadba8d1d7943f4782fc25e06999
authorJeff Hostetler <jeffhost@microsoft.com>
Fri, 25 Mar 2022 18:03:11 +0000 (25 18:03 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 25 Mar 2022 23:04:17 +0000 (25 16:04 -0700)
tree47cf5937ecd1f6c2e260a7fdc0a9f4e052bd6b9c
parent50c725d6b6f52b1c7fc4940c092d7f205cb99583
fsmonitor--daemon: use a cookie file to sync with file system

Teach fsmonitor--daemon client threads to create a cookie file
inside the .git directory and then wait until FS events for the
cookie are observed by the FS listener thread.

This helps address the racy nature of file system events by
blocking the client response until the kernel has drained any
event backlog.

This is especially important on MacOS where kernel events are
only issued with a limited frequency.  See the `latency` argument
of `FSeventStreamCreate()`.  The kernel only signals every `latency`
seconds, but does not guarantee that the kernel queue is completely
drained, so we may have to wait more than one interval.  If we
increase the latency, the system is more likely to drop events.
We avoid these issues by having each client thread create a unique
cookie file and then wait until it is seen in the event stream.

Co-authored-by: Kevin Willford <Kevin.Willford@microsoft.com>
Co-authored-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fsmonitor--daemon.c
fsmonitor--daemon.h