msyavuz opened a new pull request, #42305:
URL: https://github.com/apache/superset/pull/42305

   ### SUMMARY
   
   Under `GLOBAL_ASYNC_QUERIES` (GAQ), the Stop button in Explore did nothing: 
once a query returns `202` and the client is polling for the async result, 
aborting the request has no effect — the fetch already settled, so no 
`AbortError` fires, `chartUpdateStopped` never dispatches, and the button stays 
stuck while the query keeps running server-side. This is the case the reporting 
customer (GAQ enabled) actually hits.
   
   This makes Stop work under GAQ, on both ends:
   
   **Frontend** — thread the request's `AbortSignal` into `waitForAsyncData`. 
On abort it stops listening for the job, POSTs the cancel endpoint, and rejects 
with an `AbortError` so the existing abort handling dispatches 
`chartUpdateStopped`. The stale-response guards now check 
`controller.signal.aborted` (authoritative — the reducer nulls 
`queryController` on stop) instead of only comparing controllers.
   
   **Backend** — a new `POST /api/v1/async_event/<job_id>/cancel` revokes the 
Celery task. The job's `job_id` is now used as the Celery `task_id`, so the id 
the client already holds is directly revocable. `revoke(..., signal="SIGUSR1")` 
surfaces as `SoftTimeLimitExceeded` in the worker, which reads a cancel flag 
and emits a single terminal `cancelled` event.
   
   **Authorization** — the endpoint never trusts the client-supplied `job_id`. 
At submit time a Redis record binds `job_id → {channel_id, user_id}`; cancel 
resolves the caller's channel and user id server-side and must match both. 
Channel-and-user (not channel alone) matters for embedded guests, whose channel 
can be shared across viewers.
   
   Depends on #42270 (renders the resulting `stopped` state — without it the 
chart area is blank after a successful stop).
   
   ### BEFORE/AFTER
   
   Before (GAQ): Stop → button stuck on "Stop", query keeps running, eventually 
a blank chart.
   After (GAQ): Stop → button returns to "Update chart", the query is cancelled 
server-side, and the stopped message shows (with #42270).
   
   ### TESTING INSTRUCTIONS
   
   1. Enable `GLOBAL_ASYNC_QUERIES` with Redis + a Celery worker.
   2. Build a chart on a slow dataset (e.g. a virtual dataset `SELECT 
pg_sleep(20)`).
   3. Trigger a refresh (click the `Cached` badge) and click **Stop** while it 
loads.
   4. The button returns to "Update chart"; the worker logs the cancellation 
and no result is cached.
   
   Unit tests: `pytest tests/unit_tests/async_events/ 
tests/unit_tests/tasks/test_async_queries.py`; `npm run test -- 
asyncEvent.test.ts chartActions.test.ts`.
   
   ### ADDITIONAL INFORMATION
   
   - [x] Has associated issue: No — internal tracker
   - [x] Required feature flags: `GLOBAL_ASYNC_QUERIES`
   - [x] Changes UI
   - [ ] Includes DB Migration
   - [x] Introduces new feature or API — `POST 
/api/v1/async_event/<job_id>/cancel`
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to