[1.50][PATCH 0/9] Review request
Please review these changes for 1.50/hardknott.
Thanks,
Anuj
The following changes since commit bcd4285116ea4990f10d53698e0a81ae1e7ce24c:
test/fetch: Update urls to match upstream branch name changes (2021-10-19 22:27:00 +0100)
are available in the Git repository at:
git://push.openembedded.org/bitbake-contrib stable/1.50-next
Caner Altinbasak (1):
npmsw: Avoid race condition with multiple npm fetchers
Richard Purdie (7):
fetch2/git: Avoid races over mirror tarball creation fetch2/git: Use os.rename instead of mv
tests/runqueue: Ensure hashserv exits before deleting files
bitbake-worker: Allow shutdown/database flush of pseudo server at task
exit
bitbake-worker: Handle pseudo shutdown in Ctrl+C case
build: Make exception printing clearer
build: Ensure python stdout/stderr is logged correctly
Ross Burton (1):
fetch2: clarify the command-no-found error message
bin/bitbake-worker | 12 +++++++++++- lib/bb/build.py | 6 +++++- lib/bb/fetch2/__init__.py | 2 +- lib/bb/fetch2/git.py | 21 +++++++++++++++++++-- lib/bb/fetch2/npmsw.py | 4 ++++ lib/bb/tests/runqueue.py | 2 +- 6 files changed, 41 insertions(+), 6 deletions(-)
Signature · 1 line
2.31.1
[1.50][PATCH 1/9] fetch2/git: Avoid races over mirror tarball creation
From: Richard Purdie <[email protected]>
There is a potential race over the mirror tarballs where a partial git repo could be extracted causing fetcher failures if the tarball is being rewritten whilst another build accesses it.
Create the mirror tarball atomically to avoid this.
[YOCTO #14441]
--- lib/bb/fetch2/git.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
lib/bb/fetch2/git.py +19 -2
@@ -68,6 +68,7 @@ import subprocess import tempfile import bb import bb.progress +from contextlib import contextmanager from bb.fetch2 import FetchMethod from bb.fetch2 import runfetchcmd from bb.fetch2 import logger
@@ -414,6 +415,20 @@ class Git(FetchMethod): bb.utils.remove(tmpdir, recurse=True) def build_mirror_data(self, ud, d): + + # Create as a temp file and move atomically into position to avoid races + @contextmanager + def create_atomic(filename, d): + fd, tfile = tempfile.mkstemp(dir=os.path.dirname(filename)) + try: + yield tfile + umask = os.umask(0o666) + os.umask(umask) + os.chmod(tfile, (0o666 & ~umask)) + runfetchcmd("mv %s %s" % (tfile, filename), d) + finally: + os.close(fd) + if ud.shallow and ud.write_shallow_tarballs: if not os.path.exists(ud.fullshallow): if os.path.islink(ud.fullshallow):
@@ -424,7 +439,8 @@ class Git(FetchMethod): self.clone_shallow_local(ud, shallowclone, d) logger.info("Creating tarball of git repository") - runfetchcmd("tar -czf %s ." % ud.fullshallow, d, workdir=shallowclone) + with create_atomic(ud.fullshallow, d) as tfile: + runfetchcmd("tar -czf %s ." % tfile, d, workdir=shallowclone) runfetchcmd("touch %s.done" % ud.fullshallow, d) finally: bb.utils.remove(tempdir, recurse=True)
@@ -433,7 +449,8 @@ class Git(FetchMethod): os.unlink(ud.fullmirror) logger.info("Creating tarball of git repository") - runfetchcmd("tar -czf %s ." % ud.fullmirror, d, workdir=ud.clonedir) + with create_atomic(ud.fullmirror, d) as tfile: + runfetchcmd("tar -czf %s ." % tfile, d, workdir=ud.clonedir) runfetchcmd("touch %s.done" % ud.fullmirror, d) def clone_shallow_local(self, ud, dest, d):
Signature · 1 line
2.31.1
[1.50][PATCH 2/9] fetch2/git: Use os.rename instead of mv
In reply to Anuj MittalFrom: Richard Purdie <[email protected]>
os.rename will overwrite the destination file if present so we can use this instead of the process call overhead.
--- lib/bb/fetch2/git.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/bb/fetch2/git.py +4 -4
@@ -418,14 +418,14 @@ class Git(FetchMethod): # Create as a temp file and move atomically into position to avoid races @contextmanager - def create_atomic(filename, d): + def create_atomic(filename): fd, tfile = tempfile.mkstemp(dir=os.path.dirname(filename)) try: yield tfile umask = os.umask(0o666) os.umask(umask) os.chmod(tfile, (0o666 & ~umask)) - runfetchcmd("mv %s %s" % (tfile, filename), d) + os.rename(tfile, filename) finally: os.close(fd)
@@ -439,7 +439,7 @@ class Git(FetchMethod): self.clone_shallow_local(ud, shallowclone, d) logger.info("Creating tarball of git repository") - with create_atomic(ud.fullshallow, d) as tfile: + with create_atomic(ud.fullshallow) as tfile: runfetchcmd("tar -czf %s ." % tfile, d, workdir=shallowclone) runfetchcmd("touch %s.done" % ud.fullshallow, d) finally:
@@ -449,7 +449,7 @@ class Git(FetchMethod): os.unlink(ud.fullmirror) logger.info("Creating tarball of git repository") - with create_atomic(ud.fullmirror, d) as tfile: + with create_atomic(ud.fullmirror) as tfile: runfetchcmd("tar -czf %s ." % tfile, d, workdir=ud.clonedir) runfetchcmd("touch %s.done" % ud.fullmirror, d)
Signature · 1 line
2.31.1
[1.50][PATCH 3/9] tests/runqueue: Ensure hashserv exits before deleting files
In reply to Anuj MittalFrom: Richard Purdie <[email protected]>
We've seen races where the socket may be gone but the server is still writing out it's database. Handle that case too to avoid cleanup tracebacks.
[YOCTO #14440]
--- lib/bb/tests/runqueue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/tests/runqueue.py +1 -1
@@ -361,7 +361,7 @@ class RunQueueTests(unittest.TestCase): def shutdown(self, tempdir): # Wait for the hashserve socket to disappear else we'll see races with the tempdir cleanup - while os.path.exists(tempdir + "/hashserve.sock"): + while (os.path.exists(tempdir + "/hashserve.sock") or os.path.exists(tempdir + "cache/hashserv.db-wal")): time.sleep(0.5)
Signature · 1 line
2.31.1
[1.50][PATCH 4/9] npmsw: Avoid race condition with multiple npm fetchers
In reply to Anuj MittalFrom: Caner Altinbasak <[email protected]>
If multiple npmsw fetchers are trying to download the same npm file, one of them can try to download the file while other is calling verify. npmsw methods gets called without holding the lock, which causes race conditions in fetching and verification etc. Lock the lockfile before calling proxy fetcher methods.
--- lib/bb/fetch2/npmsw.py | 4 ++++ 1 file changed, 4 insertions(+)
lib/bb/fetch2/npmsw.py +4 -0
@@ -29,6 +29,8 @@ from bb.fetch2.npm import npm_integrity from bb.fetch2.npm import npm_localfile from bb.fetch2.npm import npm_unpack from bb.utils import is_semver +from bb.utils import lockfile +from bb.utils import unlockfile def foreach_dependencies(shrinkwrap, callback=None, dev=False): """
@@ -187,7 +189,9 @@ class NpmShrinkWrap(FetchMethod): proxy_ud = ud.proxy.ud[proxy_url] proxy_d = ud.proxy.d proxy_ud.setup_localpath(proxy_d) + lf = lockfile(proxy_ud.lockfile) returns.append(handle(proxy_ud.method, proxy_ud, proxy_d)) + unlockfile(lf) return returns def verify_donestamp(self, ud, d):
Signature · 1 line
2.31.1
[1.50][PATCH 5/9] bitbake-worker: Allow shutdown/database flush of pseudo server at task exit
In reply to Anuj MittalFrom: Richard Purdie <[email protected]>
We have a problem where pseudo server processes exist after bitbake exits and hold the pseudo database in memory. In a docker container, the processes will be killed as the container is destroyed with no warning and no opportunity to write the data to disk. This leads to permissions/inode corruptions and data loss.
Send a shutdown message to pseudo which in new versions of pseudo will flush the database, thereby fixing some of the issues people using docker containers see.
--- bin/bitbake-worker | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
bin/bitbake-worker +9 -1
@@ -16,6 +16,8 @@ import signal import pickle import traceback import queue +import shlex +import subprocess from multiprocessing import Lock from threading import Thread
@@ -145,6 +147,7 @@ def fork_off_task(cfg, data, databuilder, workerdata, fn, task, taskname, taskha # a fork() or exec*() activates PSEUDO... envbackup = {} + fakeroot = False fakeenv = {} umask = None
@@ -164,6 +167,7 @@ def fork_off_task(cfg, data, databuilder, workerdata, fn, task, taskname, taskha # We can't use the fakeroot environment in a dry run as it possibly hasn't been built if 'fakeroot' in taskdep and taskname in taskdep['fakeroot'] and not dry_run: + fakeroot = True envvars = (workerdata["fakerootenv"][fn] or "").split() for key, value in (var.split('=') for var in envvars): envbackup[key] = os.environ.get(key)
@@ -282,7 +286,11 @@ def fork_off_task(cfg, data, databuilder, workerdata, fn, task, taskname, taskha try: if dry_run: return 0 - return bb.build.exec_task(fn, taskname, the_data, cfg.profile) + ret = bb.build.exec_task(fn, taskname, the_data, cfg.profile) + if fakeroot: + fakerootcmd = shlex.split(the_data.getVar("FAKEROOTCMD")) + subprocess.run(fakerootcmd + ['-S'], check=True, stdout=subprocess.PIPE) + return ret except: os._exit(1) if not profiling:
Signature · 1 line
2.31.1
[1.50][PATCH 6/9] bitbake-worker: Handle pseudo shutdown in Ctrl+C case
In reply to Anuj MittalFrom: Richard Purdie <[email protected]>
If the build is interrupted, handle the shutdown of pseudo even in this case to avoid data corruption inside docker containers.
[YOCTO #14555]
--- bin/bitbake-worker | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
bin/bitbake-worker +6 -4
@@ -286,10 +286,12 @@ def fork_off_task(cfg, data, databuilder, workerdata, fn, task, taskname, taskha try: if dry_run: return 0 - ret = bb.build.exec_task(fn, taskname, the_data, cfg.profile) - if fakeroot: - fakerootcmd = shlex.split(the_data.getVar("FAKEROOTCMD")) - subprocess.run(fakerootcmd + ['-S'], check=True, stdout=subprocess.PIPE) + try: + ret = bb.build.exec_task(fn, taskname, the_data, cfg.profile) + finally: + if fakeroot: + fakerootcmd = shlex.split(the_data.getVar("FAKEROOTCMD")) + subprocess.run(fakerootcmd + ['-S'], check=True, stdout=subprocess.PIPE) return ret except: os._exit(1)
Signature · 1 line
2.31.1
[1.50][PATCH 7/9] fetch2: clarify the command-no-found error message
In reply to Anuj MittalFrom: Ross Burton <[email protected]>
If runfetchcmd() fails with bb.process.NotFoundError, the message output is simply "Fetch command" which doesn't really explain what the problem is.
Add "not found" to clarify what happened.
--- lib/bb/fetch2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +1 -1
@@ -871,7 +871,7 @@ def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None, workdir=None): (output, errors) = bb.process.run(cmd, log=log, shell=True, stderr=subprocess.PIPE, cwd=workdir) success = True except bb.process.NotFoundError as e: - error_message = "Fetch command %s" % (e.command) + error_message = "Fetch command %s not found" % (e.command) except bb.process.ExecutionError as e: if e.stdout: output = "output:\n%s\n%s" % (e.stdout, e.stderr)
Signature · 1 line
2.31.1
[1.50][PATCH 8/9] build: Make exception printing clearer
In reply to Anuj MittalFrom: Richard Purdie <[email protected]>
Shows:
ERROR: SystemExit(1)
instead of:
ERROR: 1
--- lib/bb/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/build.py +1 -1
@@ -703,7 +703,7 @@ def _exec_task(fn, task, d, quieterr): # logs once already so don't duplicate if verboseStdoutLogging: errprinted = True - logger.error(str(exc)) + logger.error(repr(exc)) event.fire(TaskFailed(task, fn, logfn, localdata, errprinted), localdata) return 1 finally:
Signature · 1 line
2.31.1
[1.50][PATCH 9/9] build: Ensure python stdout/stderr is logged correctly
In reply to Anuj MittalFrom: Richard Purdie <[email protected]>
Currently we see things like:
Log data follows:
| DEBUG: Executing python function do_pythontest_exit | DEBUG: Python function do_pythontest_exit finished | ERROR: 1 | This is python stdout
Whilst after the change we see things like:
Log data follows:
| DEBUG: Executing python function do_pythontest_exit | This is python stdout | DEBUG: Python function do_pythontest_exit finished | ERROR: 1
since the output is now correctly mixed with the log messages. In some cases the logging tests indicate the output is being lost entirely which is bad for debugging and makes things rather confusing.
--- lib/bb/build.py | 4 ++++ 1 file changed, 4 insertions(+)
lib/bb/build.py +4 -0
@@ -298,6 +298,10 @@ def exec_func_python(func, d, runfile, cwd=None): comp = utils.better_compile(code, func, "exec_python_func() autogenerated") utils.better_exec(comp, {"d": d}, code, "exec_python_func() autogenerated") finally: + # We want any stdout/stderr to be printed before any other log messages to make debugging + # more accurate. In some cases we seem to lose stdout/stderr entirely in logging tests without this. + sys.stdout.flush() + sys.stderr.flush() bb.debug(2, "Python function %s finished" % func) if cwd and olddir:
Signature · 1 line
2.31.1