Git development
 help / color / mirror / Atom feed
* [PATCH] maintenance: trace when auto maintenance skips due to lock
@ 2026-11-01 10:59 Pushkar Singh
  2026-11-02  8:29 ` Patrick Steinhardt
  2026-11-02 12:29 ` [PATCH v2] maintenance: improve handling of lock acquisition failures Pushkar Singh
  0 siblings, 2 replies; 5+ messages in thread
From: Pushkar Singh @ 2026-11-01 10:59 UTC (permalink / raw)
  To: git; +Cc: gitster, mail, ps, ttaylorr, Pushkar Singh

When git maintenance run --auto encounters an existing
maintenance.lock, it silently skips running maintenance and
returns successfully.

This makes it difficult to identify cases where automatic
maintenance is being skipped repeatedly, for example due to
a stale lock left behind by an interrupted maintenance
process.

Emit a Trace2 data event when automatic maintenance skips
due to an existing lock, allowing users to identify these
skips when Trace2 event logging is enabled.

Signed-off-by: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
---
 builtin/gc.c           | 2 ++
 t/t7900-maintenance.sh | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/builtin/gc.c b/builtin/gc.c
index 81cecf6b6c..e73d1f1d49 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1409,6 +1409,8 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
 		 * recursive process stack. Do not report an error in
 		 * that case.
 		 */
+		if (opts->auto_flag && errno == EEXIST)
+			trace2_data_string("maintenance", r, "lock/skip", "exists");
 		if (!opts->auto_flag && !opts->quiet)
 			warning(_("lock file '%s' exists, skipping maintenance"),
 				lock_path);
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 9d610a29fe..440eeb956d 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -387,6 +387,14 @@ test_expect_success 'loose-objects task' '
 	test_cmp packs-between packs-after
 '
 
+test_expect_success 'auto maintenance traces existing lock' '
+	test_when_finished "rm -f trace .git/objects/maintenance.lock" &&
+	: >.git/objects/maintenance.lock &&
+	GIT_TRACE2_EVENT="$PWD/trace" git maintenance run --auto &&
+	test_grep "\"event\":\"data\".*\"category\":\"maintenance\".*\"key\":\"lock/skip\".*\"value\":\"exists\"" trace &&
+	test_path_is_file .git/objects/maintenance.lock
+'
+
 test_expect_success 'maintenance.loose-objects.auto' '
 	git repack -adk &&
 	GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-02 12:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-01 10:59 [PATCH] maintenance: trace when auto maintenance skips due to lock Pushkar Singh
2026-11-02  8:29 ` Patrick Steinhardt
2026-11-02 12:23   ` Pushkar Singh
2026-11-02 12:29 ` [PATCH v2] maintenance: improve handling of lock acquisition failures Pushkar Singh
2026-11-02 12:51   ` Patrick Steinhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox