git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Carlo Arenas <carenas@gmail.com>
Cc: git@vger.kernel.org, phillip.wood@talktalk.net, avarab@gmail.com
Subject: Re: [PATCH 2/2] config.mak.dev: alternative workaround to gcc 12 warning in http.c
Date: Fri, 15 Apr 2022 18:00:33 -0700	[thread overview]
Message-ID: <xmqq35id970u.fsf@gitster.g> (raw)
In-Reply-To: <xmqqwnfp98ix.fsf@gitster.g> (Junio C. Hamano's message of "Fri, 15 Apr 2022 17:28:06 -0700")

Junio C Hamano <gitster@pobox.com> writes:

> ...  We can take
> the patch you posted and then post release we can apply the "clear
> the .finished member as we are done with the slot" fix, which is a
> good hygiene regardless of any compiler warning issue.
> ...
> At this point, my inclination is to merge these two DEVELOPER_CFLAGS
> changes before the 2.36 final gets tagged.

So, the post release longer term clean-up with log message may look
like this.

----- >8 --------- >8 --------- >8 --------- >8 -----
Subject: [PATCH] http.c: clear the 'finished' member once we are done with it

In http.c, the run_active_slot() function allows the given "slot" to
make progress by calling step_active_slots() in a loop repeatedly,
and the loop is not left until the request held in the slot
completes.

Ages ago, we used to use the slot->in_use member to get out of the
loop, which misbehaved when the request in "slot" completes (at
which time, the result of the request is copied away from the slot,
and the in_use member is cleared, making the slot ready to be
reused), and the "slot" gets reused to service a different request
(at which time, the "slot" becomes in_use again, even though it is
for a different request).  The loop terminating condition mistakenly
thought that the original request has yet to be completed.

Today's code, after baa7b67d (HTTP slot reuse fixes, 2006-03-10)
fixed this issue, uses a separate "slot->finished" member that is
set in run_active_slot() to point to an on-stack variable, and the
code that completes the request in finish_active_slot() clears the
on-stack variable via the pointer to signal that the particular
request held by the slot has completed.  It also clears the in_use
member (as before that fix), so that the slot itself can safely be
reused for an unrelated request.

One thing that is not quite clean in this arrangement is that,
unless the slot gets reused, at which point the finished member is
reset to NULL, the member keeps the value of &finished, which
becomes a dangling pointer into the stack when run_active_slot()
returns.  In finish_active_slot(), clear the finished member after
it is used to signal the run_active_slot() caller, because we know
we are done with the pointer at that point.

Also, because compilers may not be able to follow the callchain that
deep from run_active_slot() down to finish_active_slot(), clear the
finished member but make sure to limit it to the case where the
pointer still points at the on-stack variable of ours (the pointer
may be set to point at the on-stack variable of somebody else after
the slot gets reused, in which case we do not want to touch it).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 http.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/http.c b/http.c
index 229da4d148..626b4051e1 100644
--- a/http.c
+++ b/http.c
@@ -197,8 +197,10 @@ static void finish_active_slot(struct active_request_slot *slot)
 	closedown_active_slot(slot);
 	curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);
 
-	if (slot->finished != NULL)
-		(*slot->finished) = 1;
+	if (slot->finished != NULL) {
+		*slot->finished = 1;
+		slot->finished = NULL;
+	}
 
 	/* Store slot results so they can be read after the slot is reused */
 	if (slot->results != NULL) {
@@ -1367,6 +1369,9 @@ void run_active_slot(struct active_request_slot *slot)
 			select(max_fd+1, &readfds, &writefds, &excfds, &select_timeout);
 		}
 	}
+
+	if (slot->finished == &finished)
+		slot->finished = NULL;
 }
 
 static void release_active_slot(struct active_request_slot *slot)
-- 
2.36.0-rc2-233-gc1d9011153


  parent reply	other threads:[~2022-04-16  2:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15 12:39 [PATCH] ci: lock "pedantic" job into fedora 35 and other cleanup Carlo Marcelo Arenas Belón
2022-04-15 13:17 ` Ævar Arnfjörð Bjarmason
2022-04-15 13:50 ` Phillip Wood
2022-04-15 18:31 ` Junio C Hamano
2022-04-15 21:03   ` Carlo Arenas
2022-04-15 22:20     ` Junio C Hamano
2022-04-15 23:13 ` [PATCH 0/2] ci: avoid failures for pedantic job with fedora 36 Carlo Marcelo Arenas Belón
2022-04-15 23:13   ` [PATCH 1/2] config.mak.dev: workaround gcc 12 bug affecting "pedantic" CI job Carlo Marcelo Arenas Belón
2022-04-15 23:41     ` Ævar Arnfjörð Bjarmason
2022-04-16  0:08       ` Carlo Arenas
2022-04-16  0:55         ` Ævar Arnfjörð Bjarmason
2022-04-16  5:56           ` Junio C Hamano
2022-04-16 12:33             ` Ævar Arnfjörð Bjarmason
2022-04-16  0:19       ` Junio C Hamano
2022-04-15 23:56     ` Junio C Hamano
2022-04-15 23:13   ` [PATCH 2/2] config.mak.dev: alternative workaround to gcc 12 warning in http.c Carlo Marcelo Arenas Belón
2022-04-15 23:34     ` Junio C Hamano
2022-04-16  0:02       ` Carlo Arenas
2022-04-16  0:28         ` Junio C Hamano
2022-04-16  0:51           ` Carlo Arenas
2022-04-16  1:00           ` Junio C Hamano [this message]
2022-04-16 12:50             ` Ævar Arnfjörð Bjarmason
2022-04-16  1:20           ` Ævar Arnfjörð Bjarmason
2022-04-16 14:23             ` Junio C Hamano
2022-04-16  1:08         ` Ævar Arnfjörð Bjarmason

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq35id970u.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@talktalk.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).