All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul Barker" <paul@pbarker.dev>
To: "Ricardo Salveti" <ricardo.salveti@oss.qualcomm.com>,
	<bitbake-devel@lists.openembedded.org>
Subject: Re: [PATCH] fetch: Don't reuse the url data cached for a freed datastore
Date: Sun, 29 Nov 2026 20:52:23 +0000	[thread overview]
Message-ID: <DN7ZQOEUUMZN.GGXSRMAM27CB@pbarker.dev> (raw)
In-Reply-To: <20261128220333.3995114-1-ricardo.salveti@oss.qualcomm.com>

On Sat Nov 28, 2026 at 10:03 PM GMT, Ricardo Salveti wrote:
> The url data cache is keyed by the recipe file and id(d), and an entry
> stays after its datastore is freed. Python reuses the id of a freed
> object, so a new datastore of the same recipe can get the freed one's
> url data: its urls on top of the new ones, or silently its SRCREV.
>
> meta-qcom's oe-selftest has been flaky since oe-core 4746cd7138bc
> ("oeqa/utils/commands: use tinfoil in get_bb_vars"): back-to-back
> tinfoil sessions reuse one server, each parses a recipe in it, and the
> parsers forked later inherit its cache. A recipe whose BBCLASSEXTEND
> variants use different git urls then sometimes fails to parse:
>
>   The SRCREV_FORMAT variable must be set when multiple SCMs are used.
>   The SCMs are:
>   git://github.com/qualcomm-linux/kernel.git;nobranch=1;protocol=https
>   git://github.com/qualcomm-linux/kernel.git;branch=qcom-next;protocol=https
>
> Keep a weak reference to the datastore with each entry and only use the
> entry for that datastore. Dead entries stay in the cache, as before.
>
> A new test gives two datastores the same id and fails without this.
>
> Fixes: 9a5dd1be6339 ("fetch2: Fix urldata_cache key issues")
> AI-Generated: Uses Claude Code (Claude Fable 5.2)
> Signed-off-by: Ricardo Salveti <ricardo.salveti@oss.qualcomm.com>
> ---
>  lib/bb/fetch/__init__.py |  9 +++++++--
>  lib/bb/tests/fetch.py    | 23 +++++++++++++++++++++++
>  2 files changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/lib/bb/fetch/__init__.py b/lib/bb/fetch/__init__.py
> index 612336170..76e0778d1 100644
> --- a/lib/bb/fetch/__init__.py
> +++ b/lib/bb/fetch/__init__.py
> @@ -24,6 +24,7 @@ import subprocess
>  import pickle
>  import errno
>  import shlex
> +import weakref
>  import bb.utils
>  import bb.checksum
>  import bb.process
> @@ -1863,7 +1864,11 @@ class Fetch(object):
>          if cache and fn:
>              key = mc + fn + str(id(d))
>          if key in urldata_cache:
> -            self.ud = urldata_cache[key]
> +            # id() values get reused once a datastore is freed, so check the
> +            # entry was stored for this datastore
> +            cached_d, cached_ud = urldata_cache[key]
> +            if cached_d() is d:
> +                self.ud = cached_ud
>  
>          # the unpack_tracer object needs to be made available to possible nested
>          # Fetch instances (when those are created by gitsm and npmsw fetchers)
> @@ -1895,7 +1900,7 @@ class Fetch(object):
>                          pass
>  
>          if key:
> -            urldata_cache[key] = self.ud
> +            urldata_cache[key] = (weakref.ref(d), self.ud)

Hi Ricardo,

This and the above is basically the same fix I have locally after some
experimentation with Claude to try to fix bugs #15848 & #16382. This
alone isn't a complete fix for both of those, but it looks right and
it's one step closer to the fix. I can follow up with other patches.

>  
>      def localpath(self, url):
>          if url not in self.urls:
> diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
> index 104ee1f68..23ec5ddc1 100644
> --- a/lib/bb/tests/fetch.py
> +++ b/lib/bb/tests/fetch.py
> @@ -454,6 +454,29 @@ class FetcherTest(unittest.TestCase):
>          except bb.process.ExecutionError:
>              self.git(['config', 'user.name', 'Your Name'], cwd=cwd)
>  
> +class UrldataCacheTest(FetcherTest):
> +    def recipe(self, branch):
> +        d = self.d.createCopy()
> +        d.setVar("FILE", "/recipes/foo_git.bb")
> +        d.setVar("SRCREV", "82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40")
> +        d.setVar("SRC_URI", "git://git.openembedded.org/bitbake;%s;protocol=https" % branch)
> +        return d
> +
> +    def test_same_datastore(self):
> +        d = self.recipe("branch=master")
> +        self.assertIs(bb.fetch.Fetch([], d).ud, bb.fetch.Fetch([], d).ud)
> +
> +    def test_reused_datastore_id(self):
> +        # The cache key uses id(d) and Python reuses the id of a freed object,
> +        # so give two datastores of one recipe the same id
> +        with unittest.mock.patch.object(bb.fetch, "id", create=True, return_value=0) as fake_id:
> +            d1 = self.recipe("nobranch=1")
> +            bb.fetch.Fetch([], d1)
> +            d2 = self.recipe("branch=master")
> +            fetcher = bb.fetch.Fetch([], d2)
> +        self.assertTrue(fake_id.called)
> +        self.assertEqual(list(fetcher.ud), d2.getVar("SRC_URI").split())

This is better than the test case I have which messes around triggering
garbage collection, nice!

Best regards,

-- 
Paul Barker


  reply	other threads:[~2026-11-29 20:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 22:03 [PATCH] fetch: Don't reuse the url data cached for a freed datastore Ricardo Salveti
2026-11-29 20:52 ` Paul Barker [this message]
2026-11-29 21:22   ` Paul Barker

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=DN7ZQOEUUMZN.GGXSRMAM27CB@pbarker.dev \
    --to=paul@pbarker.dev \
    --cc=bitbake-devel@lists.openembedded.org \
    --cc=ricardo.salveti@oss.qualcomm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.