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

   ### SUMMARY
   `CoordinationService.listen_for_signal` runs its `check`/`on_signal` 
callbacks on a background daemon thread. For the Global Task Framework, `check` 
is `TaskManager._check_abort_status`, which queries the metastore. The thread 
has no app context, so `_in_app_context` pushes a bare one. Any deployment that 
keeps per-request state outside the app context (for example a multi-tenant 
workspace binding stored on `flask.g`) has none of that state in the listener 
thread. Every poll then raises, the listen loop logs the exception and retries, 
and the abort signal is never acted on. Abort then only works through the 
timeout timer or heartbeat paths.
   
   This adds an opt-in config hook, `BACKGROUND_THREAD_CONTEXT_FACTORY`:
   - It is called on the **calling** thread, where the context is live, and 
returns a zero-arg callable.
   - The listener thread calls that callable to get a context manager, which 
wraps the thread's whole lifetime. Entering it once, not per poll, keeps 
per-tick cost down and covers `on_signal` too.
   - The context manager pushes its own app context. Sharing the caller's is 
deliberately not done, because SQLAlchemy sessions are scoped to the app 
context.
   - Default is `None`, which is a no-op, so behaviour for existing deployments 
is unchanged.
   
   ### TESTING INSTRUCTIONS
   `pytest tests/unit_tests/coordination 
tests/unit_tests/tasks/test_manager.py`. The new test checks the factory runs 
on the calling thread and that `check` runs inside the entered context.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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