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

Re: [PATCH 2/2] fetch: no redundant error message for atomic fetch

From
Jiang Xin <worldhello.net@gmail.com>
Date
Oct 23, 2023, 23:20 UTC
Message-ID
<CANYiYbG0YFc4Hg=e+0db4NBgM2QwOLpjHjfp8WaoObNxR-=euA@mail.gmail.com>
In-Reply-To
<ZTZF3AbNNuGpy38l@tanuki>
On Mon, Oct 23, 2023 at 6:07 PM Patrick Steinhardt <ps@pks.im> wrote:
Show 43 quoted lines
>
> On Mon, Oct 23, 2023 at 05:16:20PM +0800, Jiang Xin wrote:
> > On Mon, Oct 23, 2023 at 4:27 PM Patrick Steinhardt <ps@pks.im> wrote:
> > >
> > > On Thu, Oct 19, 2023 at 10:34:33PM +0800, Jiang Xin wrote:
> > > > @@ -1775,10 +1775,8 @@ static int do_fetch(struct transport *transport,
> > > >       }
> > > >
> > > >  cleanup:
> > > > -     if (retcode && transaction) {
> > > > -             ref_transaction_abort(transaction, &err);
> > > > +     if (retcode && transaction && ref_transaction_abort(transaction, &err))
> > > >               error("%s", err.buf);
> > > > -     }
> > >
> > > Right. We already call `error()` in all cases where `err` was populated
> > > before we `goto cleanup;`, so calling it unconditionally a second time
> > > here is wrong.
> > >
> > > That being said, `ref_transaction_abort()` will end up calling the
> > > respective backend's implementation of `transaction_abort`, and for the
> > > files backend it actually ignores `err` completely. So if the abort
> > > fails, we would still end up calling `error()` with an empty string.
> >
> > The transaction_abort implementations of the two builtin refs backends
> > will not use "err“ because they never fail (always return 0). Some one
> > may want to implement their own refs backend which may use the "err"
> > variable in their "transaction_abort". So follow the pattern as
> > update-ref.c and files-backend.c to call ref_transaction_abort() is
> > safe.
> >
> > > Furthermore, it can happen that `transaction_commit` fails, writes to
> > > the buffer and then prints the error. If the abort now fails as well, we
> > > would end up printing the error message twice.
> >
> > The abort never fails so error message from transaction_commit() will
> > not reach the code.
>
> With that reasoning we could get rid of the error handling of abort
> completely as it's known not to fail. But only because it does not fail
> right now doesn't mean that it won't in the future, as the infra for it
> to fail is all in place. And in case it ever does the current code will
> run into the bug I described.

If in the future ref_transaction_abort() fails for some reason, the err variable will be filled with the error message and the previous error message will be discarded, no duplication will occur. So I think use this fix is OK.

Show 5 quoted lines
> So in my opinion, we should either refactor the code to clarify that
> this cannot fail indeed. Or do the right thing and handle the error case
> correctly, which right now we don't.
>
> Patrick
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 6 of 19 in “t5574: test porcelain output of atomic fetch”
  1. 1/2 t5574: test porcelain output of atomic fetchJiang Xin, Oct 19, 2023
  2. 2/2 fetch: no redundant error message for atomic fetchJiang Xin, Oct 19, 2023
  3. Patrick SteinhardtOct 23, 2023
  4. Jiang XinOct 23, 2023
  5. Patrick SteinhardtOct 23, 2023
  6. Jiang XinOct 23, 2023
  7. Patrick SteinhardtOct 25, 2023
  8. Junio C HamanoOct 24, 2023
  9. 0/2 jx/fetch-atomic-error-message-fixJiang Xin, Dec 14, 2023
  10. 1/2 t5574: test porcelain output of atomic fetchJiang Xin, Dec 14, 2023
  11. Patrick SteinhardtDec 15, 2023
  12. Jiang XinDec 15, 2023
  13. Junio C HamanoDec 15, 2023
  14. 2/2 fetch: no redundant error message for atomic fetchJiang Xin, Dec 14, 2023
  15. Patrick SteinhardtDec 15, 2023
  16. 0/2 fix fetch atomic error messageJiang Xin, Dec 17, 2023
  17. 1/2 t5574: test porcelain output of atomic fetchJiang Xin, Dec 17, 2023
  18. 2/2 fetch: no redundant error message for atomic fetchJiang Xin, Dec 17, 2023
  19. Patrick SteinhardtDec 18, 2023

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.