uranusjr commented on code in PR #68377:
URL: https://github.com/apache/airflow/pull/68377#discussion_r3490454230
##########
task-sdk/src/airflow/sdk/execution_time/comms.py:
##########
@@ -118,6 +122,39 @@
ReceiveMsgType = TypeVar("ReceiveMsgType", bound=BaseModel)
+class DeadlockImminentError(BaseException):
+ """
+ Raised when ``CommsDecoder.send()`` is called from the event loop thread.
+
+ Inherits from :class:`BaseException` rather than :class:`Exception` so that
+ ``contextlib.suppress(Exception)`` β used in
:func:`airflow.sdk.log.mask_secret`
+ and similar helpers β does **not** catch it. This ensures the error always
+ surfaces to the caller, pinpointing the incorrect use of a sync API from an
+ async context (e.g. ``BaseHook.get_hook()`` inside ``aexecute()``).
+
+ Fix: replace ``BaseHook.get_hook()`` with ``await BaseHook.aget_hook()``.
+ """
+
+ def __init__(self, msg: object, *, deadlock_imminent: bool) -> None:
+ import traceback
+
+ detail = (
+ "deadlock is imminent (asend() is concurrently in-flight)"
+ if deadlock_imminent
+ else "deadlock will occur as soon as another coroutine calls
asend()"
+ )
+ stack = "".join(traceback.format_stack())
+ super().__init__(
+ f"comms.send() called from the event loop thread for message
'{type(msg).__name__}' "
+ f"β {detail}. "
+ "Likely cause: BaseHook.get_hook() or BaseHook.get_connection()
was called "
+ "from inside an async task. "
+ "Use the async equivalents instead: "
+ "await BaseHook.aget_hook() or await BaseHook.aget_connection()."
+ f"\nOffending call stack:\n{stack}"
+ )
Review Comment:
Itβs probably cleaner to put the variables as attributes on the class, and
implement this string in `__str__` instead.
--
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]