Detect OSError errno EBADF and re-raise as trio.BrokenResourceError on EventFD reads

one_ring_to_rule_them_all
Guillermo Rodriguez 2025-04-22 01:51:21 -03:00
parent a553446619
commit 7766caf623
No known key found for this signature in database
GPG Key ID: 002CC5F1E6BDA53E
1 changed files with 11 additions and 4 deletions

View File

@ -163,11 +163,18 @@ class EventFD:
async with self._read_lock: async with self._read_lock:
self._cscope = trio.CancelScope() self._cscope = trio.CancelScope()
with self._cscope: with self._cscope:
try:
return await trio.to_thread.run_sync( return await trio.to_thread.run_sync(
read_eventfd, self._fd, read_eventfd, self._fd,
abandon_on_cancel=True abandon_on_cancel=True
) )
except OSError as e:
if e.errno != errno.EBADF:
raise
raise trio.BrokenResourceError
if self._cscope.cancelled_caught: if self._cscope.cancelled_caught:
raise EFDReadCancelled raise EFDReadCancelled