Skip to content

Commit 88655df

Browse files
authored
Check if temp_dir is subdir of virtualenv, to prevent problem of runtime virtualenv (#58084)
If temp_dir is a subdirectory of current virtualenv root, it will cause copying files recursively and not finishing when ray try to create runtime virtualenv. ## Description If temp_dir is a subdirectory of current virtualenv root, when we submit a task, and specify pip dependencies, ray will create a runtime virtualenv, cause copying directories recursively, and runtime virtualenv directory explosion. --------- Signed-off-by: ideal <[email protected]>
1 parent 08cad4c commit 88655df

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

python/ray/_private/parameter.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import pathlib
34
from typing import Dict, List, Optional
45

56
import ray._private.ray_constants as ray_constants
@@ -436,6 +437,22 @@ def build_error(resource, alternative):
436437
if self.temp_dir is not None and not os.path.isabs(self.temp_dir):
437438
raise ValueError("temp_dir must be absolute path or None.")
438439

440+
if self.temp_dir is not None and os.getenv("VIRTUAL_ENV"):
441+
is_relative = True
442+
try:
443+
(
444+
pathlib.Path(self.temp_dir)
445+
.resolve()
446+
.relative_to(pathlib.Path(os.getenv("VIRTUAL_ENV")).resolve())
447+
)
448+
except ValueError:
449+
is_relative = False
450+
451+
if is_relative:
452+
raise ValueError(
453+
"temp_dir must not be child directory of virtualenv root"
454+
)
455+
439456
def _format_ports(self, pre_selected_ports):
440457
"""Format the pre-selected ports information to be more human-readable."""
441458
ports = pre_selected_ports.copy()

0 commit comments

Comments
 (0)