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

Re: [PATCH v2] maintenance: improve handling of lock acquisition failures

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 2, 2026, 12:51 UTC
Message-ID
<auiHS_439EeHCGH6@pks.im>
In-Reply-To
<20261102122955.143018-2-pushkarkumarsingh1970@gmail.com>
On Mon, Nov 02, 2026 at 12:29:56PM +0000, Pushkar Singh wrote:
Show 5 quoted lines
> Changes in v2:
> - Report lock acquisition failures for manual invocations as errors.
> - Print a warning for automatic invocations while preserving successful exit status.
> - Trace the reason for all automatic lock acquisition failures, not just EEXIST.
> - Add tests for automatic and manual lock failure behavior.
This really should be two patches now:
  - One patch that changes how we handle the failure to lock.
  - One patch that introduces your trace2 string.

One note though: please wait a bit before rerolling again so that others can chime in first. You should ideally reroll at most once per day.

Show 23 quoted lines
> diff --git a/builtin/gc.c b/builtin/gc.c
> index 81cecf6b6c..9223409750 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -1402,6 +1402,8 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
>  	enum auto_gc_hook_result auto_gc_hook_result = AUTO_GC_HOOK_UNDECIDED;
>  
>  	if (repo_hold_lock_file_for_update(r, &lk, lock_path, LOCK_NO_DEREF) < 0) {
> +		int err = errno;
> +
>  		/*
>  		 * Another maintenance command is running.
>  		 *
> @@ -1409,11 +1411,29 @@ 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 && !opts->quiet)
> -			warning(_("lock file '%s' exists, skipping maintenance"),
> -				lock_path);
> +		if (opts->auto_flag) {
> +			trace2_data_string("maintenance", r, "lock/skip",
> +				(err == EEXIST) ? "exists" : strerror(err));
Why don't you use strerror(3p) for both cases?
Show 16 quoted lines
> +			if (!opts->quiet) {
> +				struct strbuf buf = STRBUF_INIT;
> +				unable_to_lock_message(lock_path, err, &buf);
> +				warning("%s", buf.buf);
> +				strbuf_release(&buf);
> +			}
> +
> +			free(lock_path);
> +			return 0;
> +		}
> +
> +		if (!opts->quiet) {
> +			struct strbuf buf = STRBUF_INIT;
> +			unable_to_lock_message(lock_path, err, &buf);
> +			error("%s", buf.buf);
> +			strbuf_release(&buf);

There's some duplication here with the auto-flag case. Can't we deduplicate that?

Thanks!
Patrick
Previous: Pushkar SinghNext: Pushkar Singh
Message 5 of 10 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. 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.