Skip to content

fix(gtf): wait for the task lock instead of failing concurrent submits - #43492

Merged
villebro merged 5 commits into
gaq-to-gtffrom
villebro/gtf-task-lock-wait
Aug 24, 2026
Merged

villebro merged 5 commits into
gaq-to-gtffrom
villebro/gtf-task-lock-wait

Conversation

@villebro

@villebro villebro commented Aug 24, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Targets gaq-to-gtf. Loading a Deck.GL chart (and dashboards generally) could fail with a spurious {"message": "Lock already taken"} error.

Several charts — or a chart's identical queries — can resolve to the same query_cache_key, so they map to the same SHARED GTF task and the same dedup_key, and submit concurrently. task_lock acquired that dedup lock fail-fast (Redis SET NX), so the first submitter won the lock and created the task, while every other concurrent submitter — which should simply join/subscribe to that shared task — hit LockAlreadyHeldException and errored out, failing the chart.

Found while testing the Deck.GL demo dashboard, where three charts share the same query object — so all three resolve to one SHARED task and submit at once; the two that lost the lock race errored with "Lock already taken".

The fix — wait for the lock instead of failing. task_lock now blocks and waits, then joins the now-existing task. The wait is delegated to CoordinationService.wait_for_signal: event-driven on the lock's release-signal Redis Stream when a coordination backend is configured (release notify()s it), and a poll fallback otherwise — reusing the same await/notify mechanism GTF task-completion already uses. It's bounded (past the TTL) so a holder that crashed without releasing is waited out via the lock's auto-expiry rather than blocking forever, and released with the acquisition's own token (ownership-checked).

Bonus — track and surface dedupe hits. Every submit that joins an existing task (a new subscriber or an existing subscriber's resubmit) now bumps a dedupe_count on the task's properties (seeded to 0 at creation, no new column). When it's > 0 the Task List Details column shows a plus icon + the count with a tooltip, so you can see when one shared task served several chart requests.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Task List Details showing the +1 dedupe indicator on hover:

image

TESTING INSTRUCTIONS

  • pytest tests/unit_tests/tasks/test_locks.py — a held lock is retried then acquired (concurrent submit joins); a lock still held past the wait window re-raises; and notify is skipped without a coordination backend.
  • pytest tests/integration_tests/tasks/commands/test_submit.py -k joins_existing — a resubmit joins the existing task and bumps dedupe_count (seeded 0 → 1).
  • npm run test -- src/pages/TaskList/TaskList.test.tsx — the Details column shows the dedupe indicator when dedupe_count > 0.
  • End-to-end: open the Deck.GL demo dashboard (or any dashboard whose charts share a query) with GLOBAL_ASYNC_QUERIES on — the charts load instead of erroring with "Lock already taken", and the shared task shows a dedupe count.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: GLOBAL_ASYNC_QUERIES
  • Changes UI (Task List Details shows a dedupe count)
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

Several charts (or a chart's identical queries) can resolve to the same
query_cache_key — hence the same SHARED task and dedup_key — and submit at once
(a Deck.GL dashboard trips this readily). task_lock acquired the dedup lock
fail-fast (SET NX), so the winner created the task while every concurrent
submitter that should simply JOIN it errored out with "Lock already taken",
failing the chart.

Make task_lock block-and-wait: retry the acquire until the holder releases, then
join the now-existing task. Bounded by the lock TTL so a holder that crashed
without releasing is waited out (the lock auto-expires) rather than blocking
forever, and released with the acquisition's own token (ownership-checked).
@dosubot dosubot Bot added the global:async-query Related to Async Queries feature label Aug 24, 2026
@bito-code-review

bito-code-review Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped - Branch Excluded

Bito didn't auto-review because the source or target branch is excluded from automatic reviews.
No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.
You can change the branch exclusion settings here, or contact your Bito workspace admin at [email protected].

@netlify

netlify Bot commented Aug 24, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 224d100
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a8cc54cbab11900086fa6fe
😎 Deploy Preview https://deploy-preview-43492--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

… poll loop

Replace the bounded retry-poll with CoordinationService.wait_for_signal: the
acquire parks on the lock's release-signal Redis Stream and retries the SET NX
when the holder releases (event-driven, no busy-poll), and release now notify()s
that stream so a waiter wakes immediately. This reuses the same await/notify
mechanism GTF task-completion already uses — the plumbing existed, the lock just
wasn't wired to it.

Both deployment modes are covered by the one call: wait_for_signal is
event-driven with a coordination backend and falls back to polling the acquire
without one (so DB-metastore deployments still wait rather than fail). notify()
is guarded on is_backend_defined() since there's no stream to signal otherwise.
The wait window is sized comfortably above the TTL + stream block interval so a
lock orphaned by a crashed holder is still waited out at TTL expiry.
Subscriber count captures distinct subscribers but misses a subscriber
resubmitting the same task, so it undercounts how often a SHARED task's work is
reused. Add a dedupe_count in the task's existing properties JSON (no new
column): seeded to 0 on creation and bumped whenever a submit finds an existing
task and joins it — whether it becomes a new subscriber or resubmits as an
existing one (both reuse the work rather than re-create it). The increment runs
under the dedup lock, so the read-modify-write can't race.

Found while testing the Deck.GL demo dashboard, where three charts share one
query object → one SHARED task with two joins (dedupe_count = 2).
When a task's dedupe_count is > 0 (other submissions reused it instead of
running a new query), show a copy icon + the count in the Details column, with a
tooltip explaining it. Conditional like the other Details indicators — unique
tasks show nothing. Adds dedupe_count to the frontend TaskProperties type.
A copy icon read as "copy to clipboard"; a plus reads as "N more submissions
joined this task", matching the dedupe semantics.
@villebro

Copy link
Copy Markdown
Member Author

/review

@bito-code-review

bito-code-review Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #49e41c

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/tasks/locks.py - 1
    • Magic numbers for wait/polling constants · Line 49-51
      Lines 49-51 define `TASK_LOCK_WAIT_SECONDS = 30` (3×10) and `TASK_LOCK_POLL_INTERVAL_SECONDS = 0.05` — magic numbers controlling wait/polling behavior. While the inline comment at line 44-48 explains the intent, the specific multiplier (3×) and poll interval (0.05 s) are not derived from any named constant or formula, making future tuning error-prone.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/tasks/locks.py - 1
  • superset-frontend/src/features/tasks/types.ts - 1
Review Details
  • Files reviewed - 8 · Commit Range: 224d100..df86a2f
    • superset-frontend/src/features/tasks/types.ts
    • superset-frontend/src/pages/TaskList/TaskList.test.tsx
    • superset-frontend/src/pages/TaskList/index.tsx
    • superset/commands/tasks/submit.py
    • superset/daos/tasks.py
    • superset/tasks/locks.py
    • tests/integration_tests/tasks/commands/test_submit.py
    • tests/unit_tests/tasks/test_locks.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@villebro
villebro merged commit 485913a into gaq-to-gtf Aug 24, 2026
60 of 61 checks passed
@villebro
villebro deleted the villebro/gtf-task-lock-wait branch August 24, 2026 23:13
@codecov

codecov Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.86%. Comparing base (ac142e0) to head (df86a2f).
⚠️ Report is 1 commits behind head on gaq-to-gtf.

Additional details and impacted files
@@              Coverage Diff               @@
##           gaq-to-gtf   #43492      +/-   ##
==============================================
- Coverage       78.91%   78.86%   -0.06%     
==============================================
  Files            2884     2883       -1     
  Lines          165197   164798     -399     
  Branches        38150    38076      -74     
==============================================
- Hits           130364   129962     -402     
- Misses          32381    32389       +8     
+ Partials         2452     2447       -5     
Flag Coverage Δ
hive 38.12% <12.50%> (+0.05%) ⬆️
mysql 57.68% <83.33%> (-0.01%) ⬇️
postgres 57.71% <83.33%> (-0.01%) ⬇️
presto 40.06% <12.50%> (+0.05%) ⬆️
python 83.54% <100.00%> (-0.09%) ⬇️
sqlite 57.40% <83.33%> (-0.01%) ⬇️
unit 73.64% <95.83%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

global:async-query Related to Async Queries feature size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant