Skip to content

fix: handle condition waiting better in thread_task_executor#1690

Merged
no23reason merged 2 commits into
gooddata:masterfrom
no23reason:dho/cq-2677-resources
Jul 16, 2026
Merged

fix: handle condition waiting better in thread_task_executor#1690
no23reason merged 2 commits into
gooddata:masterfrom
no23reason:dho/cq-2677-resources

Conversation

@no23reason

@no23reason no23reason commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

The pattern used for the condition waiting was not robust enough and was susceptible to a race condition.

This prevents that class of race condition by persisting the status and checking it when the signal is received, rather than relying on the assumption the notification always happens after all the relevant waiters are ready to receive it.

Also, do the finalizer retrieval outside of the critical section: if it fails, it no longer holds the lock forever.

JIRA: CQ-2677
risk: low

Summary by CodeRabbit

  • Bug Fixes
    • Improved task completion tracking to ensure completion waits return reliably and avoid unnecessary delays.
    • Improved cleanup handling for data retrieval tasks, helping resources be released consistently when processing finishes.

The pattern used for the condition waiting was not robust enough
and was susceptible to a race condition.

This prevents that class of race condition by persisting the status
and checking it when the signal is received, rather then relying
on the assumption the notification always happens after all the
relevant waiters are ready to receive it.

JIRA: CQ-2677
risk: low
Move the call_finalizer_middleware before the lock acquisition.
In case it fails, it no longer does so holding (and not releasing)
the lock. There is nothing in the call_finalizer_middleware itself
that would need the lock to be held.

JIRA: CQ-2677
risk: low
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f02b18b7-7e82-4dd4-a88d-221730aa8640

📥 Commits

Reviewing files that changed from the base of the PR and between 0b272b4 and 818cdff.

📒 Files selected for processing (2)
  • packages/gooddata-flight-server/src/gooddata_flight_server/server/flight_rpc/server_methods.py
  • packages/gooddata-flight-server/src/gooddata_flight_server/tasks/thread_task_executor.py

📝 Walkthrough

Walkthrough

The change adds explicit completion-state tracking to _TaskExecution waits and initializes task-result finalizer middleware before acquiring task data, while preserving callback registration and lock-release behavior.

Changes

Task result lifecycle

Layer / File(s) Summary
Explicit task completion predicate
packages/gooddata-flight-server/src/gooddata_flight_server/tasks/thread_task_executor.py
_TaskExecution tracks _done, sets it when result processing completes, and waits for the flag before returning or timing out.
Earlier finalizer initialization
packages/gooddata-flight-server/src/gooddata_flight_server/server/flight_rpc/server_methods.py
do_get_task_result creates finalizer middleware before acquiring task data and retains end-callback registration.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: hkad98, lupko, pcerny

Poem

A rabbit waits beneath the moon,
For tasks to finish, safely soon.
A flag says “done,” the locks unwind,
The finalizer starts in time.
Hop, hop—clean flows align!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main thread_task_executor condition-waiting fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.02%. Comparing base (0b272b4) to head (818cdff).

Files with missing lines Patch % Lines
..._flight_server/server/flight_rpc/server_methods.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1690   +/-   ##
=======================================
  Coverage   78.02%   78.02%           
=======================================
  Files         271      271           
  Lines       18637    18639    +2     
=======================================
+ Hits        14542    14544    +2     
  Misses       4095     4095           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@no23reason no23reason enabled auto-merge July 16, 2026 11:22
@no23reason no23reason merged commit 807d829 into gooddata:master Jul 16, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants