diff --git a/BUILD.bazel b/BUILD.bazel index def4e7c31..a44d4ad48 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1505,7 +1505,6 @@ genrule( name = "redis", srcs = [ ] + select({ - # Windows is not supported yet, so make stubs for it "@bazel_tools//src/conditions:windows": [ "@com_github_tporadowski_redis_bin//file", ], @@ -1519,7 +1518,6 @@ genrule( "redis-cli", ], cmd = select({ - # Windows is not supported yet, so make stubs for it "@bazel_tools//src/conditions:windows": """ unzip -q -o -- $(location @com_github_tporadowski_redis_bin//file) redis-server.exe redis-cli.exe && mv -f -- redis-server.exe $(location redis-server) && diff --git a/python/ray/__init__.py b/python/ray/__init__.py index 2c9033030..de10379a2 100644 --- a/python/ray/__init__.py +++ b/python/ray/__init__.py @@ -30,6 +30,10 @@ thirdparty_files = os.path.join( os.path.abspath(os.path.dirname(__file__)), "thirdparty_files") sys.path.insert(0, thirdparty_files) +if sys.platform == "win32": + import ray.compat # noqa: E402 + ray.compat.patch_redis_empty_recv() + # Expose ray ABI symbols which may be dependent by other shared # libraries such as _streaming.so. See BUILD.bazel:_raylet python_shared_lib_suffix = ".so" if sys.platform != "win32" else ".pyd" diff --git a/python/ray/compat.py b/python/ray/compat.py new file mode 100644 index 000000000..3ddb3bf8d --- /dev/null +++ b/python/ray/compat.py @@ -0,0 +1,23 @@ +import errno +import socket +import sys + + +def patch_redis_empty_recv(): + """On Windows, socket disconnect result in errors rather than empty reads. + redis-py does not handle these errors correctly. + This patch translates connection resets to empty reads as in POSIX. + """ + assert sys.platform == "win32" + import redis + + def redis_recv(sock, *args, **kwargs): + result = b"" + try: + result = redis._compat.recv(sock, *args, **kwargs) + except socket.error as ex: + if ex.errno not in [errno.ECONNRESET, errno.ECONNREFUSED]: + raise + return result + + redis.connection.recv = redis_recv