From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24928 invoked from network); 26 Jul 2021 01:46:39 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 26 Jul 2021 01:46:38 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 1ess; Sun Jul 25 21:42:37 -0400 2021 Received: from abbatoir.myfiosgateway.com (pool-74-108-56-225.nycmny.fios.verizon.net [74.108.56.225]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id a5c32f2d (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Sun, 25 Jul 2021 18:42:33 -0700 (PDT) Message-ID: <02FEF4119D2B7885F94C9503DC06C2D6@eigenstate.org> To: 9front@9front.org Date: Sun, 25 Jul 2021 21:42:31 -0400 From: ori@eigenstate.org In-Reply-To: <0C78F8861F62859962D0700334F86680@felloff.net> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: framework descriptor cache-based framework Subject: Re: [9front] git/fetch: be more robust Reply-To: 9front@9front.org Precedence: bulk Quoth cinap_lenrek@felloff.net: > so this is like a race condition? > > depending how fast the reader is able to process the message? > > the other side of the pipeline is reading the hash and then fails to locate > it in git/fs because it has not been indexed yet when it reads too fast? Kind of. git/pull consumes the output of git/fetch, and uses it to update the refs. The problem is that we can consume the output of git/fetch and update the refs, then *fail* to update the repo. For some reason, it's never bitten me (fast internet, small deltas when I pull), but it makes me uneasy that we *can* write invalid refs. > is this just a theory or is there proof that the problem is > well understood? > > if(hparse(&want[nref], sp[0]) == -1) > sysfatal("invalid hash %s", sp[0]); > - if (resolveremote(&have[nref], sp[1]) == -1) > + if (resolveremote(&have[nref], ref[nref]) == -1) > memset(&have[nref], 0, sizeof(have[nref])); > - print("remote %s %H local %H\n", sp[1], want[nref], have[nref]); > nref++; > > > wouldnt it be better to just estrdup() at the print(), then it seems > cleaner and makes the diff smaller... like: > > if (resolveremote(&have[nref], sp[1]) == -1) > memset(&have[nref], 0, sizeof(have[nref])); > - print("remote %s %H local %H\n", sp[1], want[nref], have[nref]); > + ref[nref] = estrdup(sp[1]); > nref++ Yeah, that's equivalent, and I've got no preference. Updated patch attached, with a fix for '-l': --- //.git/fs/object/28f76455d39d990b47c6e46e18158f0a9ba09d25/tree/sys/src/cmd/git/fetch.c +++ sys/src/cmd/git/fetch.c @@ -181,7 +181,7 @@ fetchpack(Conn *c) { char buf[Pktmax], *sp[3]; - char *packtmp, *idxtmp; + char *packtmp, *idxtmp, **ref; Hash h, *have, *want; int nref, refsz, first; int i, n, req, pfd; @@ -193,6 +193,7 @@ first = 1; have = eamalloc(refsz, sizeof(have[0])); want = eamalloc(refsz, sizeof(want[0])); + ref = eamalloc(refsz, sizeof(ref[0])); while(1){ n = readpkt(c, buf, sizeof(buf)); if(n == -1) @@ -213,19 +214,20 @@ continue; if(refsz == nref + 1){ refsz *= 2; - have = erealloc(have, refsz * sizeof(have[0])); - want = erealloc(want, refsz * sizeof(want[0])); + have = earealloc(have, refsz, sizeof(have[0])); + want = earealloc(want, refsz, sizeof(want[0])); + ref = earealloc(ref, refsz, sizeof(ref[0])); } if(hparse(&want[nref], sp[0]) == -1) sysfatal("invalid hash %s", sp[0]); if (resolveremote(&have[nref], sp[1]) == -1) memset(&have[nref], 0, sizeof(have[nref])); - print("remote %s %H local %H\n", sp[1], want[nref], have[nref]); + ref[nref] = estrdup(sp[1]); nref++; } if(listonly){ flushpkt(c); - return 0; + goto showrefs; } if(writephase(c) == -1) @@ -295,6 +297,15 @@ fail(packtmp, idxtmp, "could not index fetched pack: %r"); if(rename(packtmp, idxtmp, h) == -1) fail(packtmp, idxtmp, "could not rename indexed pack: %r"); + +showrefs: + for(i = 0; i < nref; i++){ + print("remote %s %H local %H\n", ref[i], want[i], have[i]); + free(ref[i]); + } + free(ref); + free(want); + free(have); return 0; }