From 7766caf623f7519c2afa3c554a3063c222c80c52 Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Tue, 22 Apr 2025 01:51:21 -0300 Subject: [PATCH] Detect OSError errno EBADF and re-raise as trio.BrokenResourceError on EventFD reads --- tractor/linux/eventfd.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tractor/linux/eventfd.py b/tractor/linux/eventfd.py index 8ddf3669..1b00a190 100644 --- a/tractor/linux/eventfd.py +++ b/tractor/linux/eventfd.py @@ -163,10 +163,17 @@ class EventFD: async with self._read_lock: self._cscope = trio.CancelScope() with self._cscope: - return await trio.to_thread.run_sync( - read_eventfd, self._fd, - abandon_on_cancel=True - ) + try: + return await trio.to_thread.run_sync( + read_eventfd, self._fd, + abandon_on_cancel=True + ) + + except OSError as e: + if e.errno != errno.EBADF: + raise + + raise trio.BrokenResourceError if self._cscope.cancelled_caught: raise EFDReadCancelled