bitbake-worker: Fix silent hang issue caused by unexpected stdout content
PATCH 1/1 bitbake-worker: Fix silent hang issue caused by unexpected stdout content
From: Yang Xu <[email protected]>
This patch addresses an issue in bitbake-worker where stdout, reserved for status reporting, is improperly accessed by child processes.
The problem occurs during the execution of parseRecipe,
which calls anonymous functions. If these functions use print-like operations, they can inadvertently output data to stdout. This unexpected data can cause the runqueue to hang silently, if the stdout buffer is flushed before exec_task is executed.
To prevent this, the patch redirects stdout to /dev/null and ensures it is flushed prior to the execution of exec_task.
--- bin/bitbake-worker | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
bin/bitbake-worker +9 -3
@@ -237,9 +237,11 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): # Let SIGHUP exit as SIGTERM signal.signal(signal.SIGHUP, sigterm_handler) - # No stdin - newsi = os.open(os.devnull, os.O_RDWR) - os.dup2(newsi, sys.stdin.fileno()) + # No stdin & stdout + # stdout is used as a status report channel and must not be used by child processes. + dumbio = os.open(os.devnull, os.O_RDWR) + os.dup2(dumbio, sys.stdin.fileno()) + os.dup2(dumbio, sys.stdout.fileno()) if umask: os.umask(umask)
@@ -305,6 +307,10 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): if not quieterrors: logger.critical(traceback.format_exc()) os._exit(1) + + sys.stdout.flush() + sys.stderr.flush() + try: if dry_run: return 0
Signature · 1 line
2.25.1
Quoted 39 lines · Yang Xu via lists.openembedded.org
From: Yang Xu <[email protected]>
This patch addresses an issue in bitbake-worker where stdout, reserved for status reporting, is improperly accessed by child processes.
The problem occurs during the execution of parseRecipe,
which calls anonymous functions. If these functions use print-like operations, they can inadvertently output data to stdout. This unexpected data can cause the runqueue to hang silently, if the stdout buffer is flushed beforeexec_taskis executed.To prevent this, the patch redirects stdout to
/dev/nulland ensures it is flushed prior to the execution ofexec_task.Signed-off-by Yang Xu <[email protected]>--- bin/bitbake-worker | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)bin/bitbake-worker +5
-3@@ -237,9 +237,11 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): # Let SIGHUP exit as SIGTERM signal.signal(signal.SIGHUP, sigterm_handler) - # No stdin - newsi = os.open(os.devnull, os.O_RDWR) - os.dup2(newsi, sys.stdin.fileno()) + # No stdin & stdout + # stdout is used as a status report channel and must not be used by child processes. + dumbio = os.open(os.devnull, os.O_RDWR) + os.dup2(dumbio, sys.stdin.fileno()) + os.dup2(dumbio, sys.stdout.fileno()) if umask: os.umask(umask)
bin/bitbake-worker def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): · line 316
Quoted 10 lines
bin/bitbake-worker +4
-0@@ -305,6 +307,10 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): if not quieterrors: logger.critical(traceback.format_exc()) os._exit(1) + + sys.stdout.flush() + sys.stderr.flush() + try: if dry_run: return 0
This looks like a good catch.
I'm wondering if we should change the code to use a different file descriptor for the communication and leave stdout/stderr alone instead...
Cheers,
Richard
Sorry, I noticed this patch has not been merged. Is there any further work that I need to complete? Or is bitbake planning to swtich to the solution that does not use stdin/stdout directly.
Thank you
Quoted 83 lines · Richard Purdie
This patch addresses an issue in bitbake-worker where stdout,
reserved for status reporting, is improperly accessed by child processes.
The problem occurs during the execution of parseRecipe,
which calls anonymous functions. If these functions use print-like operations,
they can inadvertently output data to stdout. This unexpected data can cause
the runqueue to hang silently, if the stdout buffer is flushed
before
exec_taskis executed.To prevent this, the patch redirects stdout to
/dev/nulland ensures it isflushed prior to the execution of
exec_task.Signed-off-by Yang Xu <[email protected]>---
bin/bitbake-worker | 12 +++++++++---1 file changed, 9 insertions(+), 3 deletions(-)bin/bitbake-worker +0
-0index
eba9c562..0ba18572100755--- a/bin/bitbake-worker
+++ b/bin/bitbake-worker
bin/bitbake-worker +7
-3@@ -237,9 +237,11 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): # Let SIGHUP exit as SIGTERM signal.signal(signal.SIGHUP, sigterm_handler) - # No stdin - newsi = os.open(os.devnull, os.O_RDWR) - os.dup2(newsi, sys.stdin.fileno()) + # No stdin & stdout + # stdout is used as a status report channel and must not be used by child processes. + dumbio = os.open(os.devnull, os.O_RDWR) + os.dup2(dumbio, sys.stdin.fileno()) + os.dup2(dumbio, sys.stdout.fileno()) if umask: os.umask(umask)@@ -305,6 +307,10 @@ def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): if not quieterrors: logger.critical(traceback.format_exc()) os._exit(1) + + sys.stdout.flush()
bin/bitbake-worker def fork_off_task(cfg, data, databuilder, workerdata, extraconfigdata, runtask): · line 316
Quoted 10 lines
bin/bitbake-worker +2
-0+ sys.stderr.flush() + try: if dry_run: return 0
This looks like a good catch.
I'm wondering if we should change the code to use a different file
descriptor for the communication and leave stdout/stderr alone
instead...
Cheers,
Richard