Skip to content

Commit

Permalink
fix(core): no need to alway perform an os.stat(fd)
Browse files Browse the repository at this point in the history
Performing an `os.stat(fd)` on Windows platform generate a crash because the "handler is not valid". `select` already handle this possible case and there is no actual need to perform any kind of check before. This was removed, and the linked test slightly changed.
  • Loading branch information
StephenSorriaux committed Jan 19, 2024
1 parent d983066 commit b06ffd7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 5 additions & 3 deletions kazoo/handlers/utils.py
Expand Up @@ -3,7 +3,6 @@
from collections import defaultdict
import errno
import functools
import os
import select
import selectors
import ssl
Expand Down Expand Up @@ -349,7 +348,6 @@ def fileobj_to_fd(fileobj):
raise TypeError("Invalid file object: " "{!r}".format(fileobj))
if fd < 0:
raise TypeError("Invalid file descriptor: {}".format(fd))
os.fstat(fd)
return fd


Expand Down Expand Up @@ -380,7 +378,11 @@ def selector_select(

selector = selectors_module.DefaultSelector()
for fd, events in fd_events.items():
selector.register(fd, events)
try:
selector.register(fd, events)
except (ValueError, OSError) as e:
# gevent can raise OSError
raise ValueError('Invalid event mask or fd') from e

revents, wevents, xevents = [], [], []
try:
Expand Down
8 changes: 1 addition & 7 deletions kazoo/tests/test_selectors_select.py
Expand Up @@ -3,7 +3,6 @@
to test the selector_select function.
"""

import errno
import os
import socket
import sys
Expand Down Expand Up @@ -41,12 +40,7 @@ def test_errno(self):
with open(__file__, "rb") as fp:
fd = fp.fileno()
fp.close()
try:
select([fd], [], [], 0)
except OSError as err:
self.assertEqual(err.errno, errno.EBADF)
else:
self.fail("exception not raised")
self.assertRaises(ValueError, select, [fd], [], [], 0)

def test_returned_list_identity(self):
# See issue #8329
Expand Down

0 comments on commit b06ffd7

Please sign in to comment.