[1/1] isar-apt: fix race-condition in do_cache_config

Message ID 20260603114618.3291059-1-felix.moessbauer@siemens.com
State New
Headers show
Series [1/1] isar-apt: fix race-condition in do_cache_config | expand

Commit Message

MOESSBAUER, Felix June 3, 2026, 11:46 a.m. UTC
Repo configuration operations on the isar apt have to happen while
holding the isar lock. However, bitbake executes the cleandirs operation
without holding the lock, introducing a race-condition that sporadically
breaks the build with the following error:

  Error opening config file '/isar/build/tmp/deploy/isar-apt/
  debian-trixie/apt/debian-trixie/conf/distributions': No such file
  or directory(2)

We fix this by open-coding the cleandirs logic inside the function and
by that under the lock.

Fixes: be290896 ("isar-apt: support further optional fields ...")
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
Note, that I was able to reliably produce this with the sbom test:
./scripts/run-tests.sh -t sbom

Best regards,
Felix

 meta/recipes-devtools/isar-apt/isar-apt.bb | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

MOESSBAUER, Felix June 3, 2026, 11:56 a.m. UTC | #1
On Wed, 2026-06-03 at 13:46 +0200, Felix Moessbauer wrote:
> Repo configuration operations on the isar apt have to happen while
> holding the isar lock. However, bitbake executes the cleandirs operation
> without holding the lock, introducing a race-condition that sporadically
> breaks the build with the following error:
> 
>   Error opening config file '/isar/build/tmp/deploy/isar-apt/
>   debian-trixie/apt/debian-trixie/conf/distributions': No such file
>   or directory(2)
> 
> We fix this by open-coding the cleandirs logic inside the function and
> by that under the lock.
> 
> Fixes: be290896 ("isar-apt: support further optional fields ...")

PS: Commit "Revert "Split up isar-apt into distro-arch specific
instances" probably made it much more likely to run into the race-
condition, but the race was there before.

Felix

Patch

diff --git a/meta/recipes-devtools/isar-apt/isar-apt.bb b/meta/recipes-devtools/isar-apt/isar-apt.bb
index e824bf1d..4ecbdb82 100644
--- a/meta/recipes-devtools/isar-apt/isar-apt.bb
+++ b/meta/recipes-devtools/isar-apt/isar-apt.bb
@@ -10,11 +10,15 @@  SRC_URI = "file://distributions.in"
 
 do_cache_config[lockfiles] = "${REPO_ISAR_DIR}/isar.lock"
 do_cache_config[vardeps] += "ISAR_APT_OPT_FIELD"
-do_cache_config[cleandirs] += "${REPO_ISAR_DIR}/${DISTRO}/conf"
 
 # Generate reprepro config for current distro if it doesn't exist. Once it's
 # generated, this task should do nothing.
 do_cache_config() {
+    # this part must be executed while holding the isar.lock, hence do not move
+    # it to cleandirs (these are executed without holding the lock)
+    rm -rf ${REPO_ISAR_DIR}/${DISTRO}/conf
+    mkdir -p ${REPO_ISAR_DIR}/${DISTRO}/conf
+
     repo_create "${REPO_ISAR_DIR}"/"${DISTRO}" \
         "${REPO_ISAR_DB_DIR}"/"${DISTRO}" \
         "${DEBDISTRONAME}" \