codeant-ai-for-open-source[bot] commented on code in PR #45478:
URL: https://github.com/apache/superset/pull/45478#discussion_r4317929970
##########
superset/coordination/base.py:
##########
@@ -497,9 +498,16 @@ def listen_for_signal(
:param name: optional thread name suffix for logging.
"""
stop_event = threading.Event()
+ enter_context = cls._capture_background_context()
+
+ def run() -> None:
+ with enter_context():
+ cls._run_listen_loop(
+ channel, check, on_signal, stop_event, poll_interval
+ )
Review Comment:
Yes—the concern is valid. A long-lived app context also keeps its scoped
SQLAlchemy session alive, and a failed query can leave that session unusable
for later polls. Successful queries can retain a connection too.
Keep the factory context around the listener, but clean up the scoped
session after each poll, including when `check()` raises. Cleanup should happen
**after** `on_signal` when the check succeeds, so the callback can use the
session; `db.session.remove()` is preferable to rollback alone because it also
releases the session’s connection. This preserves the propagated context while
preventing one poll’s transaction state or connection from leaking into the
next.
--
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]