Skip to contentSkip to conversation

fetch/wget: Reuse the checkstatus() urllib opener

PATCH Superseded [email protected] 2 participants 3 messages Sep 23 – Sep 28

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch/wget: Reuse the checkstatus() urllib opener

From: Etienne Cordonnier <[email protected]>

checkstatus() builds a new urllib opener with its redirect, proxy and connection cache handlers on every call, although sstate.bbclass calls it for every object in an sstate mirror check with the same settings. Keep the opener on the FetchConnectionCache, keyed on the certificate checking setting and the fetcher environment, and rebuild it only when those change. The handlers now refer to the connection cache directly rather than through the first Fetch object, so a cached opener does not keep it alive. A connection cache is only used by one thread at a time, so no locking is needed.

Checking 2,114 objects on the Yocto sstate mirror with BB_NUMBER_THREADS = "8" reduced the time to task execution from 26.9s to 25.1s on average.

AI-Generated: Uses Claude Code (Claude Opus 5.5)

---
 lib/bb/fetch/__init__.py |  2 ++
 lib/bb/fetch/wget.py     | 45 ++++++++++++++++++++++++----------------
 2 files changed, 29 insertions(+), 18 deletions(-)
lib/bb/fetch/__init__.py +2 -0
index 55ab710f3..0eb660685 100644
@@ -2090,6 +2090,8 @@ class FetchConnectionCache(object):
     """
     def __init__(self):
         self.cache = {}
+        # urllib openers built by the wget fetcher, see Wget.checkstatus()
+        self.opener_cache = {}
 
     def get_connection_name(self, host, port, connection_id=None):
         if connection_id is None:
lib/bb/fetch/wget.py +27 -18

104 lines not on this page · raw message

Signature · 1 line
2.43.0
#1 lore raw
Quoted 40 lines · On Wed, 2026-09-23 at 19:08 +0200, [email protected] wrote:

From: Etienne Cordonnier <[email protected]>

checkstatus() builds a new urllib opener with its redirect, proxy and connection cache handlers on every call, although sstate.bbclass calls it for every object in an sstate mirror check with the same settings. Keep the opener on the FetchConnectionCache, keyed on the certificate checking setting and the fetcher environment, and rebuild it only when those change. The handlers now refer to the connection cache directly rather than through the first Fetch object, so a cached opener does not keep it alive. A connection cache is only used by one thread at a time, so no locking is needed.

Checking 2,114 objects on the Yocto sstate mirror with BB_NUMBER_THREADS = "8" reduced the time to task execution from 26.9s to 25.1s on average.

AI-Generated: Uses Claude Code (Claude Opus 5.5)

---
 lib/bb/fetch/__init__.py |  2 ++
 lib/bb/fetch/wget.py     | 45 ++++++++++++++++++++++++----------------
 2 files changed, 29 insertions(+), 18 deletions(-)
lib/bb/fetch/__init__.py +2 -0
index 55ab710f3..0eb660685 100644
@@ -2090,6 +2090,8 @@ class FetchConnectionCache(object):
     """
     def __init__(self):
         self.cache = {}
+        # urllib openers built by the wget fetcher, see Wget.checkstatus()
+        self.opener_cache = {}
 
     def get_connection_name(self, host, port, connection_id=None):
         if connection_id is None:
lib/bb/fetch/wget.py +0 -0
index 972c84048..9cb4a4f32 100644

lib/bb/fetch/wget.py class Wget(FetchMethod): · line 181

Quoted 4 lines
lib/bb/fetch/wget.py +1 -0
@@ -178,23 +178,24 @@ class Wget(FetchMethod):
     def checkstatus(self, fetch, ud, d, try_again=True):
         check_certs = self.check_certs(d)
         newenv = bb.fetch.get_fetcher_environment(d)
+        connection_cache = fetch.connection_cache

Hi,

Is this refactoring a necessary part of the urllib opener caching? If not it would be better to move it to a separate commit so that this patch is easier to understand.

Best regards,

Signature · 1 line
Paul Barker
#2 lore raw

Hi Paul,

making the opener cache safe to use does depend on it: without the rename, caching the opener would leak a Fetch object per distinct opener built. So the two changes are tied together.
I've split the change in 2 patches as you suggested.

Étienne

Quoted 60 lines · Paul Barker
Quoted 12 lines · On Wed, 2026-09-23 at 19:08 +0200, [email protected] wrote:

From: Etienne Cordonnier <[email protected]>

checkstatus() builds a new urllib opener with its redirect, proxy and connection cache handlers on every call, although sstate.bbclass calls it for every object in an sstate mirror check with the same settings. Keep the opener on the FetchConnectionCache, keyed on the certificate checking setting and the fetcher environment, and rebuild it only when those change. The handlers now refer to the connection cache directly rather than through the first Fetch object, so a cached opener does not keep it alive. A connection cache is only used by one thread at a time, so no locking is needed.

Quoted 1 line

Checking 2,114 objects on the Yocto sstate mirror with BB_NUMBER_THREADS

= "8"

Quoted 14 lines

reduced the time to task execution from 26.9s to 25.1s on average.

AI-Generated: Uses Claude Code (Claude Opus 5.5)

---
 lib/bb/fetch/__init__.py |  2 ++
 lib/bb/fetch/wget.py     | 45 ++++++++++++++++++++++++----------------
 2 files changed, 29 insertions(+), 18 deletions(-)
lib/bb/fetch/__init__.py +0 -0
index 55ab710f3..0eb660685 100644

lib/bb/fetch/__init__.py class FetchConnectionCache(object): · line 2093

Quoted 4 lines
lib/bb/fetch/__init__.py +1 -0
@@ -2090,6 +2090,8 @@ class FetchConnectionCache(object):
     """
     def __init__(self):
         self.cache = {}
+        # urllib openers built by the wget fetcher, see

Wget.checkstatus()

lib/bb/fetch/wget.py class Wget(FetchMethod): · line 181

Quoted 13 lines
lib/bb/fetch/__init__.py +1 -0
+        self.opener_cache = {}
 
     def get_connection_name(self, host, port, connection_id=None):
         if connection_id is None:
lib/bb/fetch/wget.py +1 -0
index 972c84048..9cb4a4f32 100644
@@ -178,23 +178,24 @@ class Wget(FetchMethod):
     def checkstatus(self, fetch, ud, d, try_again=True):
         check_certs = self.check_certs(d)
         newenv = bb.fetch.get_fetcher_environment(d)
+        connection_cache = fetch.connection_cache

Hi,

Is this refactoring a necessary part of the urllib opener caching? If not it would be better to move it to a separate commit so that this patch is easier to understand.

Best regards,

--
Paul Barker