summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Sorriaux <stephen.sorriaux@gmail.com>2023-04-24 14:35:42 -0400
committerStephen Sorriaux <stephen.sorriaux@gmail.com>2023-04-24 18:12:39 -0400
commitb39ca3748e1f3ea1cd393b52b9466fbfc2b29670 (patch)
tree0afb1a317c7d88710c919f1e92d489a92ad6eb5f
parent2c36d699fbf0569f490d5bfa66fa85fbdc68dea3 (diff)
downloadkazoo-b39ca3748e1f3ea1cd393b52b9466fbfc2b29670.tar.gz
fix(core): no need to alway perform an `os.stat(fd)`
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.
-rw-r--r--kazoo/handlers/utils.py8
-rw-r--r--kazoo/tests/test_selectors_select.py8
2 files changed, 6 insertions, 10 deletions
diff --git a/kazoo/handlers/utils.py b/kazoo/handlers/utils.py
index 2abe1ff..9db26c4 100644
--- a/kazoo/handlers/utils.py
+++ b/kazoo/handlers/utils.py
@@ -3,7 +3,6 @@
from collections import defaultdict
import errno
import functools
-import os
import select
import selectors
import ssl
@@ -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
@@ -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:
diff --git a/kazoo/tests/test_selectors_select.py b/kazoo/tests/test_selectors_select.py
index 19b224d..99dd44a 100644
--- a/kazoo/tests/test_selectors_select.py
+++ b/kazoo/tests/test_selectors_select.py
@@ -3,7 +3,6 @@ The official python select function test case copied from python source
to test the selector_select function.
"""
-import errno
import os
import socket
import sys
@@ -41,12 +40,7 @@ class SelectTestCase(unittest.TestCase):
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