ferruzzi commented on code in PR #64022:
URL: https://github.com/apache/airflow/pull/64022#discussion_r3114288851


##########
airflow-core/src/airflow/jobs/triggerer_job_runner.py:
##########
@@ -202,33 +202,47 @@ def _exit_gracefully(self, signum, frame) -> None:
             sys.exit(os.EX_SOFTWARE)
 
     def _execute(self) -> int | None:
-        self.log.info("Starting the triggerer")
-        self.register_signals()
-        stats_factory = stats_utils.get_stats_factory(Stats)
-        Stats.initialize(factory=stats_factory)
+        # Mark as server context for secrets backend detection when handling 
GetConnection
+        # requests from the TriggerRunner subprocess (needs MetastoreBackend).
+        # The subprocess explicitly sets _AIRFLOW_PROCESS_CONTEXT=client to 
prevent
+        # inheriting server privileges (runs user trigger/callback code).
+        # Similar to DagProcessorManager / DagProcessor child pattern.
+        _prev_ctx = os.environ.get("_AIRFLOW_PROCESS_CONTEXT")
+        os.environ["_AIRFLOW_PROCESS_CONTEXT"] = "server"
         try:
-            # Kick off runner sub-process without DB access
-            self.trigger_runner = TriggerRunnerSupervisor.start(
-                job=self.job,
-                capacity=self.capacity,
-                logger=log,
-                queues=self.queues,
-            )
+            self.log.info("Starting the triggerer")
+            self.register_signals()
+            stats_factory = stats_utils.get_stats_factory(Stats)
+            Stats.initialize(factory=stats_factory)
+            self.trigger_runner = None
+            try:
+                # Kick off runner sub-process without DB access
+                self.trigger_runner = TriggerRunnerSupervisor.start(
+                    job=self.job,
+                    capacity=self.capacity,
+                    logger=log,
+                    queues=self.queues,
+                )
 
-            # Run the main DB comms loop in this process
-            self.trigger_runner.run()
-            return self.trigger_runner._exit_code
-        except Exception:
-            self.log.exception("Exception when executing 
TriggerRunnerSupervisor.run")
-            raise
+                # Run the main DB comms loop in this process
+                self.trigger_runner.run()
+                return self.trigger_runner._exit_code
+            except Exception:
+                self.log.exception("Exception when executing 
TriggerRunnerSupervisor.run")
+                raise
+            finally:
+                self.log.info("Waiting for triggers to clean up")

Review Comment:
   Typo or a term I'm not familiar with.  "subtproc"?  should maybe be subproc 
or subprocess??



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

Reply via email to