diff --git a/SOURCES/0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch b/SOURCES/0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch index 154792d..e62969b 100644 --- a/SOURCES/0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch +++ b/SOURCES/0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch @@ -1,10 +1,10 @@ -From aa77652e8ec5d7cbe14e09133e58a45d92cf3720 Mon Sep 17 00:00:00 2001 +From 90efeb281ee1f78f6ac1d83b659397f4ec82c1c6 Mon Sep 17 00:00:00 2001 From: Derek Horton Date: Fri, 5 Aug 2022 15:02:37 -0500 Subject: [PATCH] Use thread.join(timeout) to avoid busy waiting and simplify interval event posting logic -Resolves: rhbz#2137005 +Resolves: rhbz#2104199 (cherry picked from commit 478930cca7a8d4acf21aef0715e42052315cb24e) --- diff --git a/SOURCES/0004-fix-ensure-_run_data-is-called-on-a-thread.patch b/SOURCES/0004-fix-ensure-_run_data-is-called-on-a-thread.patch new file mode 100644 index 0000000..ee7505f --- /dev/null +++ b/SOURCES/0004-fix-ensure-_run_data-is-called-on-a-thread.patch @@ -0,0 +1,50 @@ +From 780394e905186c9c95a8e90aa5107f698a5b1f5b Mon Sep 17 00:00:00 2001 +From: Link Dupont +Date: Wed, 16 Nov 2022 13:35:12 -0500 +Subject: [PATCH] fix: ensure _run_data is called on a thread + +_run_data is not async-aware, so declaring it as an async function and +running it in an event loop results in synchronous execution of the +entire function. This means the Send function only returns once the +entire _run_data function has completed. Running it on the event loop +using run_in_executor runs the function call in a thread executor pool, +ensuring that it doesn't block the calling thread. This is a fairly +naive solution; a better implementation might be able to pass a future +into _run_data, immediately fulfill that future, let the calling +function (Send) return the RPC receipt, and continue running _run_data. + +(cherry picked from commit 03e7385199140fde0686f1031459f7f61e5f735b) + +Resolves: RHBZ#2142992 + +Signed-off-by: Link Dupont +--- + rhc_worker_playbook/server.py | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/rhc_worker_playbook/server.py b/rhc_worker_playbook/server.py +index e41482d..cf282c5 100644 +--- a/rhc_worker_playbook/server.py ++++ b/rhc_worker_playbook/server.py +@@ -17,6 +17,7 @@ import json + import uuid + import atexit + import asyncio ++import functools + from subprocess import Popen, PIPE + from requests import Request + from concurrent import futures +@@ -138,11 +139,11 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer): + ''' + + loop = asyncio.new_event_loop() +- loop.run_until_complete(self._run_data(request)) ++ loop.run_in_executor(executor=None, func=functools.partial(self._run_data, request)) + + return yggdrasil_pb2.Receipt() + +- async def _run_data(self, request): ++ def _run_data(self, request): + # load configuration + config = _loadConfig() + diff --git a/SPECS/rhc-worker-playbook.spec b/SPECS/rhc-worker-playbook.spec index cb56e96..9e7668d 100644 --- a/SPECS/rhc-worker-playbook.spec +++ b/SPECS/rhc-worker-playbook.spec @@ -5,7 +5,7 @@ Name: rhc-worker-playbook Summary: Red Hat connect worker for launching Ansible Runner Version: 0.1.8 -Release: 4%{?dist} +Release: 5%{?dist} License: GPLv2+ Source: rhc-worker-playbook-0.1.8.tar.gz Source1: https://github.com/ansible-collections/community.general/archive/%{community_general_version}/ansible-collection-community-general-%{community_general_version}.tar.gz @@ -17,6 +17,7 @@ Source2: https://github.com/ansible-collections/ansible.posix/archive/%{ansib Patch0001: 0001-fix-Execute-playbook-asynchronously.patch Patch0002: 0002-Do-not-busy-wait-when-playbook-is-running.patch Patch0003: 0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch +Patch0004: 0004-fix-ensure-_run_data-is-called-on-a-thread.patch ExclusiveArch: %{go_arches} @@ -43,6 +44,7 @@ Python-based worker for Red Hat connect, used to launch Ansible playbooks via An %patch0001 -p1 %patch0002 -p1 %patch0003 -p1 +%patch0004 -p1 pushd community.general-%{community_general_version} rm -vr .github .azure-pipelines @@ -110,8 +112,11 @@ mkdir -p %{buildroot}%{_localstatedir}/log/rhc-worker-playbook/ansible %doc %changelog -* Sat Oct 22 2022 Gael Chamoulaud 0.1.8-4 -- Use thread.join(timeout) to avoid busy waiting and simplify interval event posting logic (rhbz#2137005) +* Wed Nov 23 2022 Link Dupont 0.1.8-5 +- Ensure _run_data is called on a thread (RHBZ#2142992) + +* Thu Oct 20 2022 Gael Chamoulaud 0.1.8-4 +- Use thread.join(timeout) to avoid busy waiting and simplify interval event posting logic (rhbz#2104199) * Fri Aug 05 2022 Gael Chamoulaud 0.1.8-3 - Do not busy-wait when playbook is running (rhbz#2104199)