public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul Tarjan via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>,
	Paul Tarjan <github@paulisageek.com>,
	Paul Tarjan <github@paulisageek.com>
Subject: [PATCH v6 08/10] fsmonitor: add tests for Linux
Date: Wed, 25 Feb 2026 20:17:14 +0000	[thread overview]
Message-ID: <8fec92d5b4c86da5f85797516c10812150fed557.1772050636.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2147.v6.git.git.1772050636.gitgitgadget@gmail.com>

From: Paul Tarjan <github@paulisageek.com>

Add a smoke test that verifies the filesystem actually delivers
inotify events to the daemon.  On some configurations (e.g.,
overlayfs with older kernels), inotify watches succeed but events
are never delivered.  The daemon cookie wait will time out, but
every subsequent test would fail.  Skip the entire test file early
when this is detected.

Add a test that exercises rapid nested directory creation to verify
the daemon correctly handles the EEXIST race between recursive scan
and queued inotify events.  When IN_MASK_CREATE is available and a
directory watch is added during recursive registration, the kernel
may also deliver a queued IN_CREATE event for the same directory.
The second inotify_add_watch() returns EEXIST, which must be treated
as harmless.  An earlier version of the listener crashed in this
scenario.

Signed-off-by: Paul Tarjan <github@paulisageek.com>
---
 t/meson.build                |  8 +++-
 t/t7527-builtin-fsmonitor.sh | 89 +++++++++++++++++++++++++++++++++---
 2 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/t/meson.build b/t/meson.build
index 19e8306298..85ef2ae2fa 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -1210,12 +1210,18 @@ test_environment = script_environment
 test_environment.set('GIT_BUILD_DIR', git_build_dir)
 
 foreach integration_test : integration_tests
+  per_test_kwargs = test_kwargs
+  # The fsmonitor tests start daemon processes that in some environments
+  # can hang.  Set a generous timeout to prevent CI from blocking.
+  if fs.stem(integration_test) == 't7527-builtin-fsmonitor'
+    per_test_kwargs += {'timeout': 1800}
+  endif
   test(fs.stem(integration_test), shell,
     args: [ integration_test ],
     workdir: meson.current_source_dir(),
     env: test_environment,
     depends: test_dependencies + bin_wrappers,
-    kwargs: test_kwargs,
+    kwargs: per_test_kwargs,
   )
 endforeach
 
diff --git a/t/t7527-builtin-fsmonitor.sh b/t/t7527-builtin-fsmonitor.sh
index 409cd0cd12..774da5ac60 100755
--- a/t/t7527-builtin-fsmonitor.sh
+++ b/t/t7527-builtin-fsmonitor.sh
@@ -10,9 +10,58 @@ then
 	test_done
 fi
 
+# Verify that the filesystem delivers events to the daemon.
+# On some configurations (e.g., overlayfs with older kernels),
+# inotify watches succeed but events are never delivered.  The
+# cookie wait will time out and the daemon logs a trace message.
+#
+# Use "timeout" (if available) to guard each step against hangs.
+maybe_timeout () {
+	if type timeout >/dev/null 2>&1
+	then
+		timeout "$@"
+	else
+		shift
+		"$@"
+	fi
+}
+verify_fsmonitor_works () {
+	git init test_fsmonitor_smoke || return 1
+
+	GIT_TRACE_FSMONITOR="$PWD/smoke.trace" &&
+	export GIT_TRACE_FSMONITOR &&
+	maybe_timeout 30 \
+		git -C test_fsmonitor_smoke fsmonitor--daemon start \
+			--start-timeout=10
+	ret=$?
+	unset GIT_TRACE_FSMONITOR
+	if test $ret -ne 0
+	then
+		rm -rf test_fsmonitor_smoke smoke.trace
+		return 1
+	fi
+
+	maybe_timeout 10 \
+		test-tool -C test_fsmonitor_smoke fsmonitor-client query \
+			--token 0 >/dev/null 2>&1
+	maybe_timeout 5 \
+		git -C test_fsmonitor_smoke fsmonitor--daemon stop 2>/dev/null
+	! grep -q "cookie_wait timed out" "$PWD/smoke.trace" 2>/dev/null
+	ret=$?
+	rm -rf test_fsmonitor_smoke smoke.trace
+	return $ret
+}
+
+if ! verify_fsmonitor_works
+then
+	skip_all="filesystem does not deliver fsmonitor events (container/overlayfs?)"
+	test_done
+fi
+
 stop_daemon_delete_repo () {
 	r=$1 &&
-	test_might_fail git -C $r fsmonitor--daemon stop &&
+	test_might_fail maybe_timeout 30 \
+		git -C $r fsmonitor--daemon stop 2>/dev/null
 	rm -rf $1
 }
 
@@ -67,7 +116,7 @@ start_daemon () {
 			export GIT_TEST_FSMONITOR_TOKEN
 		fi &&
 
-		git $r fsmonitor--daemon start &&
+		git $r fsmonitor--daemon start --start-timeout=10 &&
 		git $r fsmonitor--daemon status
 	)
 }
@@ -520,6 +569,28 @@ test_expect_success 'directory changes to a file' '
 	grep "^event: dir1$" .git/trace
 '
 
+test_expect_success 'rapid nested directory creation' '
+	test_when_finished "git fsmonitor--daemon stop; rm -rf rapid" &&
+
+	start_daemon --tf "$PWD/.git/trace" &&
+
+	# Rapidly create nested directories to exercise race conditions
+	# where directory watches may be added concurrently during
+	# event processing and recursive scanning.
+	for i in $(test_seq 1 20)
+	do
+		mkdir -p "rapid/nested/dir$i/subdir/deep" || return 1
+	done &&
+
+	# Give the daemon time to process all events
+	sleep 1 &&
+
+	test-tool fsmonitor-client query --token 0 &&
+
+	# Verify daemon is still running (did not crash)
+	git fsmonitor--daemon status
+'
+
 # The next few test cases exercise the token-resync code.  When filesystem
 # drops events (because of filesystem velocity or because the daemon isn't
 # polling fast enough), we need to discard the cached data (relative to the
@@ -910,7 +981,10 @@ test_expect_success "submodule absorbgitdirs implicitly starts daemon" '
 start_git_in_background () {
 	git "$@" &
 	git_pid=$!
-	git_pgid=$(ps -o pgid= -p $git_pid)
+	git_pgid=$(ps -o pgid= -p $git_pid 2>/dev/null ||
+		awk '{print $5}' /proc/$git_pid/stat 2>/dev/null) &&
+	git_pgid="${git_pgid## }" &&
+	git_pgid="${git_pgid%% }"
 	nr_tries_left=10
 	while true
 	do
@@ -921,15 +995,16 @@ start_git_in_background () {
 		fi
 		sleep 1
 		nr_tries_left=$(($nr_tries_left - 1))
-	done >/dev/null 2>&1 &
+	done >/dev/null 2>&1 3>&- 4>&- 5>&- 6>&- 7>&- &
 	watchdog_pid=$!
 	wait $git_pid
 }
 
 stop_git () {
-	while kill -0 -- -$git_pgid
+	test -n "$git_pgid" || return 0
+	while kill -0 -- -$git_pgid 2>/dev/null
 	do
-		kill -- -$git_pgid
+		kill -- -$git_pgid 2>/dev/null
 		sleep 1
 	done
 }
@@ -944,7 +1019,7 @@ stop_watchdog () {
 
 test_expect_success !MINGW "submodule implicitly starts daemon by pull" '
 	test_atexit "stop_watchdog" &&
-	test_when_finished "stop_git; rm -rf cloned super sub" &&
+	test_when_finished "set +m; stop_git; rm -rf cloned super sub" &&
 
 	create_super super &&
 	create_sub sub &&
-- 
gitgitgadget


  parent reply	other threads:[~2026-02-25 20:17 UTC|newest]

Thread overview: 129+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-30  8:14 [PATCH] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2025-12-30 11:38 ` Junio C Hamano
2025-12-30 12:08 ` [PATCH v2] " Paul Tarjan via GitGitGadget
2025-12-30 12:55   ` [PATCH v3] " Paul Tarjan via GitGitGadget
2025-12-31 17:41     ` [PATCH v4] " Paul Tarjan via GitGitGadget
2026-01-05 12:07       ` Patrick Steinhardt
2026-02-20 22:18         ` Junio C Hamano
2026-02-21 16:15           ` Paul Tarjan
2026-02-21 17:07             ` Junio C Hamano
2026-02-23  6:34               ` Patrick Steinhardt
2026-02-23 15:42                 ` Junio C Hamano
2026-02-23 15:46                   ` Patrick Steinhardt
2026-02-24  1:34                     ` Paul Tarjan
2026-02-24  8:03                       ` Patrick Steinhardt
2026-02-24  1:31       ` [PATCH v5] " Paul Tarjan via GitGitGadget
2026-02-24  8:03         ` Patrick Steinhardt
2026-02-25 20:17         ` [PATCH v6 00/10] " Paul Tarjan via GitGitGadget
2026-02-25 20:17           ` [PATCH v6 01/10] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-02-25 21:01             ` Junio C Hamano
2026-02-25 20:17           ` [PATCH v6 02/10] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-02-25 20:17           ` [PATCH v6 03/10] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-02-25 20:17           ` [PATCH v6 04/10] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-02-25 21:13             ` Junio C Hamano
2026-02-27  6:31               ` Paul Tarjan
2026-02-27 16:44                 ` Junio C Hamano
2026-02-28  0:28                   ` Paul Tarjan
2026-02-25 21:17             ` Junio C Hamano
2026-02-27  6:31               ` Paul Tarjan
2026-02-25 20:17           ` [PATCH v6 05/10] fsmonitor: deduplicate IPC path logic for Unix platforms Paul Tarjan via GitGitGadget
2026-02-25 21:30             ` Junio C Hamano
2026-02-27  6:31               ` Paul Tarjan
2026-02-25 20:17           ` [PATCH v6 06/10] fsmonitor: deduplicate settings " Paul Tarjan via GitGitGadget
2026-02-25 21:31             ` Junio C Hamano
2026-02-27  6:31               ` Paul Tarjan
2026-02-25 20:17           ` [PATCH v6 07/10] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-02-25 20:17           ` Paul Tarjan via GitGitGadget [this message]
2026-02-25 20:17           ` [PATCH v6 09/10] run-command: add close_fd_above_stderr option Paul Tarjan via GitGitGadget
2026-02-25 21:41             ` Junio C Hamano
2026-02-25 20:17           ` [PATCH v6 10/10] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-02-26  0:27           ` [PATCH v7 00/10] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-02-26  0:27             ` [PATCH v7 01/10] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-03-04  7:42               ` Patrick Steinhardt
2026-03-04 18:17                 ` Paul Tarjan
2026-02-26  0:27             ` [PATCH v7 02/10] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-03-04  7:42               ` Patrick Steinhardt
2026-03-04 18:17                 ` Paul Tarjan
2026-02-26  0:27             ` [PATCH v7 03/10] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-03-04  7:42               ` Patrick Steinhardt
2026-03-04 18:17                 ` Paul Tarjan
2026-02-26  0:27             ` [PATCH v7 04/10] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-03-04  7:42               ` Patrick Steinhardt
2026-03-04 18:17                 ` Paul Tarjan
2026-02-26  0:27             ` [PATCH v7 05/10] fsmonitor: deduplicate IPC path logic for Unix platforms Paul Tarjan via GitGitGadget
2026-03-04  7:42               ` Patrick Steinhardt
2026-03-04 18:17                 ` Paul Tarjan
2026-02-26  0:27             ` [PATCH v7 06/10] fsmonitor: deduplicate settings " Paul Tarjan via GitGitGadget
2026-03-04  7:43               ` Patrick Steinhardt
2026-03-04 18:17                 ` Paul Tarjan
2026-02-26  0:27             ` [PATCH v7 07/10] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-04  7:43               ` Patrick Steinhardt
2026-03-04 18:17                 ` Paul Tarjan
2026-02-26  0:27             ` [PATCH v7 08/10] fsmonitor: add tests " Paul Tarjan via GitGitGadget
2026-03-04  7:43               ` Patrick Steinhardt
2026-03-04 18:17                 ` Paul Tarjan
2026-02-26  0:27             ` [PATCH v7 09/10] run-command: add close_fd_above_stderr option Paul Tarjan via GitGitGadget
2026-02-26  0:27             ` [PATCH v7 10/10] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-03-04  7:43               ` Patrick Steinhardt
2026-03-04 18:17                 ` Paul Tarjan
2026-02-26 15:34             ` [PATCH v7 00/10] fsmonitor: implement filesystem change listener for Linux Junio C Hamano
2026-03-04 18:15             ` [PATCH v8 00/12] " Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 01/12] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 02/12] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 03/12] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 04/12] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 05/12] fsmonitor: rename fsm-ipc-darwin.c to fsm-ipc-unix.c Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 06/12] fsmonitor: rename fsm-settings-darwin.c to fsm-settings-unix.c Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 07/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 08/12] run-command: add close_fd_above_stderr option Paul Tarjan via GitGitGadget
2026-03-04 20:51                 ` Junio C Hamano
2026-03-05  0:49                   ` [PATCH v8 09/12] " Paul Tarjan
2026-03-05  4:13                     ` Junio C Hamano
2026-03-05  6:38                       ` [PATCH v9 09/12] run-command: add pre-exec callback for child processes Paul Tarjan
2026-03-04 18:15               ` [PATCH v8 09/12] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 10/12] fsmonitor: add timeout to daemon stop command Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 11/12] fsmonitor: add tests for Linux Paul Tarjan via GitGitGadget
2026-03-04 18:15               ` [PATCH v8 12/12] fsmonitor: convert shown khash to strset in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05  0:51               ` [PATCH v9 00/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 01/12] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 02/12] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 03/12] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 04/12] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 05/12] fsmonitor: rename fsm-ipc-darwin.c to fsm-ipc-unix.c Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 06/12] fsmonitor: rename fsm-settings-darwin.c to fsm-settings-unix.c Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 07/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 08/12] run-command: add pre-exec callback for child processes Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 09/12] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 10/12] fsmonitor: add timeout to daemon stop command Paul Tarjan via GitGitGadget
2026-03-05  0:51                 ` [PATCH v9 11/12] fsmonitor: add tests for Linux Paul Tarjan via GitGitGadget
2026-03-05  0:52                 ` [PATCH v9 12/12] fsmonitor: convert shown khash to strset in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05  1:16                 ` [PATCH v10 00/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 01/12] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 02/12] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 03/12] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 04/12] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 05/12] fsmonitor: rename fsm-ipc-darwin.c to fsm-ipc-unix.c Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 06/12] fsmonitor: rename fsm-settings-darwin.c to fsm-settings-unix.c Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 07/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 08/12] run-command: add pre-exec callback for child processes Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 09/12] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 10/12] fsmonitor: add timeout to daemon stop command Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 11/12] fsmonitor: add tests for Linux Paul Tarjan via GitGitGadget
2026-03-05  1:16                   ` [PATCH v10 12/12] fsmonitor: convert shown khash to strset in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05  6:55                   ` [PATCH v11 00/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 01/12] fsmonitor: fix khash memory leak in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 02/12] fsmonitor: fix hashmap memory leak in fsmonitor_run_daemon Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 03/12] compat/win32: add pthread_cond_timedwait Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 04/12] fsmonitor: use pthread_cond_timedwait for cookie wait Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 05/12] fsmonitor: rename fsm-ipc-darwin.c to fsm-ipc-unix.c Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 06/12] fsmonitor: rename fsm-settings-darwin.c to fsm-settings-unix.c Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 07/12] fsmonitor: implement filesystem change listener for Linux Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 08/12] run-command: add close_fd_above_stderr option Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 09/12] fsmonitor: close inherited file descriptors and detach in daemon Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 10/12] fsmonitor: add timeout to daemon stop command Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 11/12] fsmonitor: add tests for Linux Paul Tarjan via GitGitGadget
2026-03-05  6:55                     ` [PATCH v11 12/12] fsmonitor: convert shown khash to strset in do_handle_client Paul Tarjan via GitGitGadget
2026-03-05  7:37                     ` [PATCH v11 00/12] fsmonitor: implement filesystem change listener for Linux Patrick Steinhardt
2026-03-05 14:15                       ` Paul Tarjan
2026-03-25 20:00                       ` Junio C Hamano
2025-12-30 15:37   ` [PATCH v2] " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8fec92d5b4c86da5f85797516c10812150fed557.1772050636.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=github@paulisageek.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox