Skip to content

Commit 807d829

Browse files
authored
Merge pull request #1690 from no23reason/dho/cq-2677-resources
fix: handle condition waiting better in thread_task_executor
2 parents 0b272b4 + 818cdff commit 807d829

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

packages/gooddata-flight-server/src/gooddata_flight_server/server/flight_rpc/server_methods.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def do_get_task_result(
101101
f"While the result exists, it is of an unexpected type: {type(result).__name__} ",
102102
).to_internal_error()
103103

104+
finalizer = FlightServerMethods.call_finalizer_middleware(context)
105+
104106
rlock, data = result.acquire_data()
105107

106108
def _on_end(_: pyarrow.ArrowException | None) -> None:
@@ -121,7 +123,6 @@ def _on_end(_: pyarrow.ArrowException | None) -> None:
121123
# log and sink these Exceptions - not much to do
122124
_LOGGER.error("do_get_close_failed", exc_info=True)
123125

124-
finalizer = FlightServerMethods.call_finalizer_middleware(context)
125126
finalizer.register_on_end(_on_end)
126127

127128
if isinstance(data, pyarrow.Table):

packages/gooddata-flight-server/src/gooddata_flight_server/tasks/thread_task_executor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class _TaskExecution:
158158
"_result_future",
159159
"_lock",
160160
"_completed",
161+
"_done",
161162
"_stats",
162163
)
163164

@@ -189,6 +190,8 @@ def __init__(
189190
# all these are protected using the lock
190191
self._result_future: Future[Union[TaskResult, TaskError]] | None = None
191192
self._completed: threading.Condition = threading.Condition(self._lock)
193+
# indicates the task actually finished
194+
self._done: bool = False
192195

193196
@property
194197
def task(self) -> Task:
@@ -235,6 +238,7 @@ def on_result_done(self, fut: Future) -> None:
235238

236239
with self._lock:
237240
execution_result = self._cb.process_task_result(self, self._result_future)
241+
self._done = True
238242
self._completed.notify_all()
239243

240244
self._complete_execution_span(execution_result)
@@ -291,7 +295,7 @@ def cancel(self) -> bool:
291295

292296
def wait_for_completion(self, timeout: float | None = None) -> None:
293297
with self._lock:
294-
completed = self._completed.wait(timeout=timeout)
298+
completed = self._completed.wait_for(lambda: self._done, timeout=timeout)
295299

296300
if not completed:
297301
raise TaskWaitTimeoutError(task_id=self._task.task_id, cmd=self._task.cmd)

0 commit comments

Comments
 (0)