public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] buildchroot: Lock-protect apt/dpkg operations
@ 2018-02-14 19:42 Jan Kiszka
  2018-02-15  8:16 ` Alexander Smirnov
  2018-02-15  9:39 ` Alexander Smirnov
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Kiszka @ 2018-02-14 19:42 UTC (permalink / raw)
  To: isar-users, Alexander Smirnov; +Cc: Larson, Chris

From: Jan Kiszka <jan.kiszka@siemens.com>

When running multiple build targets in parallel, they will compete for
access on the package database while the related commands do not wait
but fail immediately.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

Fixes parallel builds (CI setup) for me.

I just recalled that Chris was reporting the same issue a long time ago,
but his suggestion to lock down whole do_build was not that well
received...

 meta/recipes-devtools/buildchroot/files/build.sh | 32 +++++++++++++++---------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/meta/recipes-devtools/buildchroot/files/build.sh b/meta/recipes-devtools/buildchroot/files/build.sh
index 023a6d6..048f76f 100644
--- a/meta/recipes-devtools/buildchroot/files/build.sh
+++ b/meta/recipes-devtools/buildchroot/files/build.sh
@@ -2,17 +2,9 @@
 #
 # This software is a part of ISAR.
 # Copyright (C) 2015-2017 ilbers GmbH
+# Copyright (c) 2018 Siemens AG
 
-# Make sure that we have latest isar-apt content.
-# Options meaning:
-#   Dir::Etc::sourcelist - specifies which source to be used
-#   Dir::Etc::sourceparts - disables looking for the other sources
-#   APT::Get::List-Cleanup - do not erase obsolete packages list for
-#                            upstream in '/var/lib/apt/lists'
-apt-get update \
-    -o Dir::Etc::sourcelist="sources.list.d/multistrap-isar-apt.list" \
-    -o Dir::Etc::sourceparts="-" \
-    -o APT::Get::List-Cleanup="0"
+set -e
 
 # Go to build directory
 cd $1
@@ -26,8 +18,24 @@ install_cmd="apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y
 # Allow unauthenticated feeds
 install_cmd="${install_cmd} --allow-unauthenticated"
 
-# Install all build deps
-mk-build-deps -t "${install_cmd}" -i -r debian/control
+(
+    # Lock-protected because apt and dpkg do not wait in case of contention
+    flock 42 || exit 1
+
+    # Make sure that we have latest isar-apt content.
+    # Options meaning:
+    #   Dir::Etc::sourcelist - specifies which source to be used
+    #   Dir::Etc::sourceparts - disables looking for the other sources
+    #   APT::Get::List-Cleanup - do not erase obsolete packages list for
+    #                            upstream in '/var/lib/apt/lists'
+    apt-get update \
+        -o Dir::Etc::sourcelist="sources.list.d/multistrap-isar-apt.list" \
+        -o Dir::Etc::sourceparts="-" \
+        -o APT::Get::List-Cleanup="0"
+
+    # Install all build deps
+    mk-build-deps -t "${install_cmd}" -i -r debian/control
+) 42>/dpkg.lock
 
 # If autotools files have been created, update their timestamp to
 # prevent them from being regenerated
-- 
2.13.6

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-02-15  9:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-14 19:42 [PATCH] buildchroot: Lock-protect apt/dpkg operations Jan Kiszka
2018-02-15  8:16 ` Alexander Smirnov
2018-02-15  8:46   ` Jan Kiszka
2018-02-15  9:39 ` Alexander Smirnov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox