Repository navigation
fix(gtf): async chart-data hardening (abort teardown, private properties, review follow-ups) - #43678
Conversation
A task that registers an on_abort handler (e.g. chart-data query cancellation) starts a background abort listener parked in a blocking Redis XREAD (_LISTEN_BLOCK_MS=1000). SignalListener.stop() joined that thread, so it waited out the full block — adding ~1s to every such task at teardown (Celery reported ~1.1s while the task body, started_at→ended_at, was ~0.1s). stop() now nudges the stream so the blocked read returns at once and the loop observes the stop flag. Abort detection is unchanged (a real signal still wakes the read; the loop checks the stop flag before the predicate, so the wake nudge can never fire a handler).
Task `properties` are returned by the Task REST API, so internal runtime state must not leak to consumers. Introduce a reserved `private` sub-dict (initialized empty on every task) that the API strips entirely; everything top-level (progress_*, is_abortable, error_message, timeout, ...) stays public. - superset-core: add PrivateProperties; move celery_task_id / cancel_query_id / cancel_database_id under TaskProperties['private']. - Task.update_private_properties(): merge into the private bucket (so the Celery-id write at pickup and the cancel-handle write during execution don't clobber each other); create_task seeds an empty private bucket. - scheduler / context write the job id and engine cancel handle into private; the reaper reads them from there; the serializer drops the whole private key. - Documented public-vs-internal properties in the Tasks guide. Replaces the earlier per-task hidden-keys approach with a simpler namespaced bucket.
|
Bito Automatic Review Skipped - Branch Excluded |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## gaq-to-gtf #43678 +/- ##
==============================================
- Coverage 79.29% 75.07% -4.22%
==============================================
Files 2885 2890 +5
Lines 166311 166978 +667
Branches 38420 38423 +3
==============================================
- Hits 131874 125364 -6510
- Misses 31950 39075 +7125
- Partials 2487 2539 +52
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The status_changes read floors its cursors to whole seconds for MySQL's second-precision changed_on, but the 202 handshake captured its cursor with an unfloored datetime.now(). On a second-precision metastore a task created and completed within the same second could have changed_on earlier than the microsecond cursor and be skipped under the >= bound, hanging the client's waiter until its stale timeout. Add a shared floored_status_cursor() helper and use it at the 202 capture site and both read sites so the precision contract lives in one place.
|
The flagged issue is correct. The current test setup does not properly simulate a blocked listener, meaning the test could pass even if the wake mechanism is broken. To resolve this, you should modify the test to ensure the listener is actually blocked in I have checked the PR comments and there are no other comments to address. Would you like me to implement the fix for this test? |
…s tiers
Establishes a durable task-state hierarchy:
- Public `properties` (top-level): progress/status, is_abortable, timeout,
dedupe_count, execution_mode, error_message — visible to subscribers.
- `properties.private` (internal, surfaced only in debug mode) with two
structurally isolated namespaces so a task's freeform key can never collide
with a framework key:
- private.framework: celery_task_id, exception_type, stack_trace (framework)
- private.task: cancel_query_id/cancel_database_id and other task-execution
handles (freeform)
- `payload`: end-user results (cache_key, tracking URLs), shown in the info bubble.
Backend: PrivateProperties split into framework/task (superset-core types);
Task.update_properties recursively merges the private subtree; new
update_framework_private / update_task_private write APIs; error_update +
context/reap route exception_type/stack_trace into private.framework;
set_cancellation writes private.task; get_properties gates the whole private
bucket on debug mode (current_app.debug via task_internals_visible) and now
returns TaskProperties; create_task seeds both namespaces.
Frontend: TaskProperties.private typed; status icon / stack-trace popover read
private.framework; the info bubble renders a separate 'Internal' section (the
private bucket) below the results payload when present.
Replaces the earlier flat always-stripped private bucket.
…rdening - related_subscribers now joins through a base-filtered visible-task subquery (new TaskDAO.visible_task_ids_query), so the subscriber filter dropdown only lists subscribers of tasks the caller can see rather than enumerating all users. Adds an integration test (gamma sees only itself; admin sees both). - superset-websocket README gains a 'Production hardening checklist' calling out ALLOWED_ORIGINS, secure/SameSite/domain JWT-cookie flags, connection caps (maxTotalConnections/maxConnectionsPerChannel/maxSocketBufferBytes), and keepalive timeouts — all already configurable, now surfaced for operators.
- Harden the private-subtree merge against a malformed (non-dict) persisted value: extract a shared merge_private_subtree() helper (used by Task.update_properties and TaskContext.set_cancellation) that treats a non-dict subtree/namespace as empty instead of raising TypeError on unpacking. private is framework-managed, so this only guards corrupted/tampered rows. - Fire the abort-listener wake nudge on a daemon thread so a synchronous Redis write on a degraded backend (no socket timeout) can't block stop() past its bounded 2s join + daemon-reap fallback. - Strengthen the coordination test: exercise a listener actually parked in a blocking XREAD and assert it terminates promptly on stop() via the wake; add a test that stop() stays bounded even when the wake hangs; cover malformed-private merge tolerance.
The runtime code always stored and read cancel_query_id/cancel_database_id under private.task (query-task-specific state), but the FrameworkPrivateProperties TypedDict and the tasks.md 'private.framework' bullet wrongly listed them as framework keys. Correct both: framework holds only celery_task_id + exception_type/stack_trace (common to every task); the chart-data cancel handle is a task-type-specific key under the freeform private.task namespace.
The websocket server's package-lock.json had 77 tarball URLs resolving to
Apple-internal registries (31 npm.apple.com, 46 artifacts.apple.com/artifactory)
— a lockfile regenerated on an internal machine whose npm proxied the public
registry. Apache CI can't reach those hosts, so 'npm ci' crashed
('Exit handler never called!'). Rewrite the resolved URLs to registry.npmjs.org;
integrity hashes are unchanged (the internal artifactory proxy serves the same
upstream tarballs) and every package is public. No dependency versions change.
Review (sadpandajoe) on apache#43689: - realtime.ts: resolve the ws URL against the page URL so a root-relative endpoint (e.g. /superset-ws behind a same-origin proxy) still connects with tab_id (new URL(url) alone rejected it and dropped the tab id -> tab-targeted status never reached the socket). http(s) is normalized to ws(s). - realtime.ts: reconnect when this tab's id changes (a duplicated tab reassigned on a TAB_ID_DENIED collision) so the socket re-registers under the new per-tab channel; useTabId now exposes subscribeTabIdChange and notifies on reassignment. Failing test: - test_reap fixture wrote the engine cancel handle at top-level properties, but the apache#43678 task-state hierarchy moved cancel_query_id/cancel_database_id into private.task (where the reaper reads them); fixed the helper to use update_task_private so the orphan-query-cancel assertion passes. Tests: realtime root-relative-url + tab-id-change reconnect; shim mock gains subscribeTabIdChange. All frontend + touched python unit tests green.
SUMMARY
Async-path hardening for the Global Task Framework, from the pre-merge review + performance investigation. Targets
gaq-to-gtf.Landed in this PR so far:
Abort-listener teardown no longer delays task completion. A task that registers an
on_aborthandler (e.g. chart-data query cancellation) starts a background abort listener parked in a blocking RedisXREAD(_LISTEN_BLOCK_MS = 1000).SignalListener.stop()joined that thread, so it waited out the full block — adding ~1s to every such task at teardown (Celery reported ~1.1s while the task body,started_at→ended_at, was ~0.1s).stop()now nudges the stream so the blocked read returns at once. Abort detection is unchanged: a real signal still wakes the read, and the loop checks the stop flag before the predicate, so the wake nudge can never fire a handler.Internal task state moved into a
privateproperties bucket. Taskpropertiesare returned by the Task REST API, so internal runtime state must not leak. A reservedproperties["private"]sub-dict (seeded empty on every task) holds framework plumbing —celery_task_id,cancel_query_id,cancel_database_id— and the API strips it wholesale. Everything top-level (progress_*,is_abortable,error_message,timeout, …) stays public.Task.update_private_properties()merges into the bucket so independent writers (job-id at pickup, cancel-handle during execution) don't clobber each other. Addresses the review's "public/private metadata boundary" finding.Planned on this branch (rolling into this PR):
async_queries.pycaptures the 202 cursor with an unflooreddatetime.now(), while the status-changes read floors to whole seconds for MySQL's second-precisionchanged_on— so a same-second task transition can be missed under the>=bound. Fix the cursor floor (polling-mode correctness).status_changespolling while the socket is healthy; rely on push + a task-id-aware resync on (re)connect (which also sidesteps the cursor entirely on the ws path).related_subscribersscoped to visible tasks (currently global).TESTING INSTRUCTIONS
GET /api/v1/task/<uuid>—propertiesmust not containcelery_task_id/cancel_query_id/cancel_database_id;progress_*/error_messageremain.pytest tests/unit_tests/tasks/ tests/unit_tests/coordination/.ADDITIONAL INFORMATION
GLOBAL_TASK_FRAMEWORK(+GLOBAL_ASYNC_QUERIESfor the chart-data path)