Skip to content

Commit

Permalink
[Core] Check that temp_dir must be absolute path. (ray-project#36431)
Browse files Browse the repository at this point in the history
ray.init accepts a _temp_dir arg. The arg should be absolute path because it makes no sense to have a "relative path" on all nodes. However the code did not check that and proceeds as if it is absolute path. This makes the init code to hang and timeout.

Example issues for treating it as absolute: the latest_session symlink links to the temp_dir and if it is relative path it won't work.

Signed-off-by: Ruiyang Wang <rywang014@gmail.com>
Signed-off-by: e428265 <arvind.chandramouli@lmco.com>
  • Loading branch information
rynewang authored and arvind-chandra committed Aug 31, 2023
1 parent e4e83a0 commit 31c7ee3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion python/ray/_private/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class RayParams:
raylet_socket_name: If provided, it will specify the socket path
used by the raylet process.
temp_dir: If provided, it will specify the root temporary
directory for the Ray process.
directory for the Ray process. Must be an absolute path.
storage: Specify a URI for persistent cluster-wide storage. This storage path
must be accessible by all nodes of the cluster, otherwise an error will be
raised.
Expand Down Expand Up @@ -428,6 +428,9 @@ def build_error(resource, alternative):
"serialization. Upgrade numpy if using with ray."
)

if self.temp_dir is not None and not os.path.isabs(self.temp_dir):
raise ValueError("temp_dir must be absolute path or None.")

def _format_ports(self, pre_selected_ports):
"""Format the pre-selected ports information to be more human-readable."""
ports = pre_selected_ports.copy()
Expand Down
4 changes: 2 additions & 2 deletions python/ray/_private/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,8 @@ def init(
_redis_password: Prevents external clients without the password
from connecting to Redis if provided.
_temp_dir: If provided, specifies the root temporary
directory for the Ray process. Defaults to an OS-specific
conventional location, e.g., "/tmp/ray".
directory for the Ray process. Must be an absolute path. Defaults to an
OS-specific conventional location, e.g., "/tmp/ray".
_metrics_export_port: Port number Ray exposes system metrics
through a Prometheus endpoint. It is currently under active
development, and the API is subject to change.
Expand Down
7 changes: 7 additions & 0 deletions python/ray/tests/test_ray_init_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ def test_get_ray_address_from_environment(monkeypatch):
)


# https://github.com/ray-project/ray/issues/36431
def test_temp_dir_must_be_absolute(shutdown_only):
# This test fails with a relative path _temp_dir.
with pytest.raises(ValueError):
ray.init(_temp_dir="relative_path")


if __name__ == "__main__":
import sys

Expand Down

0 comments on commit 31c7ee3

Please sign in to comment.