git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 2/2] maintenance: trace lock acquisition failures

From
Pushkar Singh <pushkarkumarsingh1970@gmail.com>
Date
Nov 18, 2026, 19:07 UTC
Message-ID
<20261118190735.3928-3-pushkarkumarsingh1970@gmail.com>
In-Reply-To
<20261118190735.3928-1-pushkarkumarsingh1970@gmail.com>

When automatic or scheduled maintenance fails to acquire the maintenance lock, emit a Trace2 data event describing the reason for the failure.

The event uses the "maintenance" category and "lock/skip" key, with the OS error reported via strerror(err).

This makes it easier to identify cases where automatic or scheduled maintenance is repeatedly skipped due to lock acquisition failures.

Signed-off-by: Pushkar Singh <pushkarkumarsingh1970@gmail.com>
---
 builtin/gc.c           |  4 ++++
 t/t7900-maintenance.sh | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
diff --git a/builtin/gc.c b/builtin/gc.c
index d423b68cce..32d6f9c473 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1413,6 +1413,10 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
 		 * another scheduled run is already running. Do not
 		 * report an error in either case.
 		 */
+		if (opts->auto_flag || opts->schedule)
+			trace2_data_string("maintenance", r, "lock/skip",
+					   strerror(err));
+
 		if (!opts->quiet) {
 			struct strbuf buf = STRBUF_INIT;
 
diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
index 4e519e4a5d..959c99a51f 100755
--- a/t/t7900-maintenance.sh
+++ b/t/t7900-maintenance.sh
@@ -423,6 +423,35 @@ test_expect_success 'scheduled maintenance skips with existing lock' '
 	test_path_is_file .git/objects/maintenance.lock
 '
 
+test_expect_success 'auto maintenance traces existing lock' '
+	test_when_finished "rm -f trace.txt .git/objects/maintenance.lock" &&
+	: >.git/objects/maintenance.lock &&
+	GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
+		git maintenance run --auto --quiet &&
+	test_trace2_data maintenance lock/skip "File exists" <trace.txt &&
+	test_path_is_file .git/objects/maintenance.lock
+'
+
+test_expect_success 'scheduled maintenance traces existing lock' '
+	test_when_finished "rm -f trace.txt err .git/objects/maintenance.lock" &&
+	: >.git/objects/maintenance.lock &&
+	GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
+		git maintenance run --schedule=hourly 2>err &&
+	test_must_be_empty err &&
+	test_trace2_data maintenance lock/skip "File exists" <trace.txt &&
+	test_path_is_file .git/objects/maintenance.lock
+'
+
+test_expect_success 'manual maintenance does not trace lock/skip' '
+	test_when_finished "rm -f trace.txt err .git/objects/maintenance.lock" &&
+	: >.git/objects/maintenance.lock &&
+	GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
+		test_must_fail git maintenance run --quiet 2>err &&
+	test_must_be_empty err &&
+	! grep -e "\"category\":\"maintenance\",\"key\":\"lock/skip\"" trace.txt &&
+	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
Previous: Pushkar SinghNext: Aniket Gupta
Message 12 of 13 in “maintenance: trace when auto maintenance skips due to lock”
  1. maintenance: trace when auto maintenance skips due to lockPushkar Singh, Nov 1, 2026
  2. Patrick SteinhardtNov 2, 2026
  3. Pushkar SinghNov 2, 2026
  4. maintenance: improve handling of lock acquisition failuresPushkar Singh, Nov 2, 2026
  5. Patrick SteinhardtNov 2, 2026
  6. Pushkar SinghNov 3, 2026
  7. 0/2 maintenance: improve lock acquisition failure handlingPushkar Singh, Nov 4, 2026
  8. 1/2 maintenance: report lock acquisition failuresPushkar Singh, Nov 4, 2026
  9. 2/2 maintenance: trace lock acquisition failuresPushkar Singh, Nov 4, 2026
  10. 0/2 maintenance: improve lock acquisition failure handlingPushkar Singh, Nov 18, 2026
  11. 1/2 maintenance: handle lock acquisition failures correctlyPushkar Singh, Nov 18, 2026
  12. 2/2 maintenance: trace lock acquisition failuresPushkar Singh, Nov 18, 2026
  13. Aniket GuptaNov 4, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.