gh-146205: Check the errno with != 0 in close impls in select module by aisk · Pull Request #146206 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_devpoll.py
9 changes: 9 additions & 0 deletions Lib/test/test_epoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ def test_close(self):
self.assertRaises(ValueError, epoll.register, fd, select.EPOLLIN)
self.assertRaises(ValueError, epoll.unregister, fd)

def test_close_error(self):
# gh-146205: close() should raise OSError if underlying fd is invalid
epoll = select.epoll()
fd = epoll.fileno()
os.close(fd)
with self.assertRaises(OSError) as cm:
epoll.close()
self.assertEqual(cm.exception.errno, errno.EBADF)

def test_fd_non_inheritable(self):
epoll = select.epoll()
self.addCleanup(epoll.close)
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_kqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ def test_close(self):
# operations must fail with ValueError("I/O operation on closed ...")
self.assertRaises(ValueError, kqueue.control, None, 4)

def test_close_error(self):
# gh-146205: close() should raise OSError if underlying fd is invalid
kqueue = select.kqueue()
fd = kqueue.fileno()
os.close(fd)
with self.assertRaises(OSError) as cm:
kqueue.close()
self.assertEqual(cm.exception.errno, errno.EBADF)

def test_fd_non_inheritable(self):
kqueue = select.kqueue()
self.addCleanup(kqueue.close)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a bug where :meth:`select.epoll.close`, :meth:`select.kqueue.close`,
and :meth:`select.devpoll.close` silently ignored errors.
15 changes: 9 additions & 6 deletions Modules/selectmodule.c
Loading