Skip to content

Commit c6c2ba3

Browse files
committed
Deal with potential hanging syscalls in simple_test
1 parent 3ed7f36 commit c6c2ba3

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

test/simple_test.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import random
2626
import secrets
2727
import io
28+
from concurrent.futures import ProcessPoolExecutor, TimeoutError as FuturesTimeoutError
2829

2930
faulthandler.enable()
3031

@@ -61,6 +62,28 @@ def statvfs(path):
6162
statvfs = os.statvfs
6263

6364

65+
def is_mount_then_statvfs(mount_point: str) -> bool:
66+
try:
67+
ismounted: bool = ismount(mount_point)
68+
if not ismounted:
69+
return False
70+
# This forces initialization of FUSE
71+
statvfs(mount_point)
72+
return True
73+
except EnvironmentError:
74+
traceback.print_exc()
75+
return False
76+
77+
78+
def is_mount_then_statvfs_with_timeout(mount_point: str, timeout: float = 1.0) -> bool:
79+
with ProcessPoolExecutor(max_workers=1) as executor:
80+
future = executor.submit(is_mount_then_statvfs, mount_point)
81+
try:
82+
return future.result(timeout=timeout)
83+
except FuturesTimeoutError:
84+
return False
85+
86+
6487
def securefs_mount(
6588
data_dir: str,
6689
mount_point: str,
@@ -97,14 +120,10 @@ def securefs_mount(
97120
)
98121
try:
99122
for _ in range(300):
100-
try:
101-
if ismount(mount_point):
102-
statvfs(mount_point)
103-
if sys.platform == "darwin":
104-
time.sleep(0.01)
105-
return p
106-
except EnvironmentError:
107-
traceback.print_exc()
123+
if is_mount_then_statvfs_with_timeout(mount_point, timeout=10.0):
124+
if sys.platform == "darwin":
125+
time.sleep(0.01)
126+
return p
108127
time.sleep(0.005)
109128
raise TimeoutError(f"Failed to mount {repr(mount_point)} after many attempts")
110129
except:

0 commit comments

Comments
 (0)