uranusjr commented on code in PR #68377:
URL: https://github.com/apache/airflow/pull/68377#discussion_r3412153540
##########
task-sdk/src/airflow/sdk/execution_time/comms.py:
##########
@@ -216,15 +255,64 @@ def _make_frame(self, msg: SendMsgType) -> _RequestFrame:
def send(self, msg: SendMsgType) -> ReceiveMsgType | None:
"""Send a request to the parent and block until the response is
received."""
+ # Two-level detection for sync send() called from the event loop
thread.
+ # Raises SyncSendOnEventLoopError (BaseException subclass) so it
escapes
+ # contextlib.suppress(Exception) in mask_secret() and other helpers.
+ #
+ # Level 1 — wrong pattern (broader): send() is on the event loop
thread at
+ # all, detected via the stored loop thread id from the last asend()
call.
+ # Level 2 — imminent deadlock (precise): _thread_lock is also
currently held
+ # by a thread-pool worker from a concurrent asend() round-trip.
+ #
+ # Typical cause: BaseHook.get_hook() or BaseHook.get_connection()
called
+ # from inside an async task / aexecute().
+ # Fix: use 'await BaseHook.aget_hook()' or 'await
BaseHook.aget_connection()'.
+ _on_loop_thread = self._loop_thread_id is not None and
threading.get_ident() == self._loop_thread_id
Review Comment:
```suggestion
_on_loop_thread = threading.get_ident() == self._loop_thread_id
```
I think this is enough? `get_ident()` can never return None so if
`self._loop_thread_id` is None the part after `and` would never be True anyway.
Actually I think the entire added block can be simplified to
```python
on_loop_thread = False
if threading.get_ident() == self._loop_thread_id:
with contextlib.suppress(RuntimeError):
on_loop_thread = bool(asyncio.get_running_loop())
--
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]