From: Patrick Steinhardt <ps@pks.im>
To: Justin Tobler <jltobler@gmail.com>
Cc: git@vger.kernel.org, likui@oschina.cn
Subject: Re: [PATCH] builtin/fetch: avoid aborting closed reference transaction
Date: Mon, 24 Mar 2025 11:40:30 +0100 [thread overview]
Message-ID: <Z-E2ns9VziejSLB2@pks.im> (raw)
In-Reply-To: <20250321004437.505461-1-jltobler@gmail.com>
On Thu, Mar 20, 2025 at 07:44:37PM -0500, Justin Tobler wrote:
> As part of the reference transaction commit phase, the transaction is
> set to a closed state regardless of whether it was successful of not.
> Attempting to abort a closed transaction via `ref_transaction_abort()`
> results in a `BUG()`.
Yeah, this is one of the more intricate parts of ref transactions, and
it has been biting me several times in the past. It feels somewhat
similar in spirit to how the `ref_iterator` used to automatically free
itself once it has reached its end, which led to the same class of bugs
due to the interface being way too intricate.
So I wonderer whether we should refactor this interface in the same way:
instead of automatically freeing the transaction on commit/abort, we'd
never do so and require the caller to always free it themselves. This
would make it way easier to use because we can now unconditionally free
the transaction everywhere.
That wouldn't help with the fixed bug though, which is that we call
abort after a failed commit even though the transaction was already
aborted.
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 95fd0018b9..f2555731f4 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -1867,8 +1867,15 @@ static int do_fetch(struct transport *transport,
> goto cleanup;
>
> retcode = ref_transaction_commit(transaction, &err);
> - if (retcode)
> + if (retcode) {
> + /*
> + * Explicitly handle transaction cleanup to avoid
> + * aborting an already closed transaction.
> + */
> + ref_transaction_free(transaction);
> + transaction = NULL;
> goto cleanup;
> + }
> }
>
> commit_fetch_head(&fetch_head);
Okay, makes sense.
Thanks for the fix!
Patrick
next prev parent reply other threads:[~2025-03-24 10:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <37599b30-dee2-4a36-8129-04fe5f6b633e.likui@oschina.cn>
2025-03-20 8:36 ` `git fetch origin --prune --atomic` core dumped 李葵
2025-03-20 16:10 ` Justin Tobler
2025-03-21 0:44 ` [PATCH] builtin/fetch: avoid aborting closed reference transaction Justin Tobler
2025-03-24 10:40 ` Patrick Steinhardt [this message]
2025-03-24 15:10 ` Justin Tobler
2025-03-24 15:25 ` Patrick Steinhardt
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=Z-E2ns9VziejSLB2@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=jltobler@gmail.com \
--cc=likui@oschina.cn \
/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;
as well as URLs for NNTP newsgroup(s).