Skip to content

Commit 830debb

Browse files
authored
Merge pull request #1795 from dandi/bf-test-nwb2asset-hang
bf: pass aiohttp timeouts to fsspec to fix test hang
2 parents 2d10167 + a6109be commit 830debb

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

dandi/misctypes.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,27 @@ def open(self) -> IO[bytes]:
345345
# Optional dependency:
346346
import fsspec
347347

348+
from aiohttp import ClientTimeout
349+
348350
# We need to call open() on the return value of fsspec.open() because
349351
# otherwise the filehandle will only be opened when used to enter a
350352
# context manager.
351-
return cast(IO[bytes], fsspec.open(self.url, mode="rb").open())
353+
#
354+
# Pass explicit timeouts to aiohttp to prevent indefinite hangs in
355+
# fsspec's sync() wrapper. Without these, a stalled connection to S3
356+
# (or minio in tests) causes fsspec's background IO thread to block
357+
# forever, which in turn blocks the calling thread in
358+
# threading.Event.wait() — see https://github.com/fsspec/filesystem_spec/issues/1666
359+
return cast(
360+
IO[bytes],
361+
fsspec.open(
362+
self.url,
363+
mode="rb",
364+
client_kwargs={
365+
"timeout": ClientTimeout(total=120, sock_read=60, sock_connect=30)
366+
},
367+
).open(),
368+
)
352369

353370
def get_size(self) -> int:
354371
return self.size

dandi/tests/test_metadata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ def test_nwb2asset(simple2_nwb: Path) -> None:
11451145
)
11461146

11471147

1148+
@pytest.mark.timeout(120)
11481149
@pytest.mark.xfail(reason="https://github.com/dandi/dandi-cli/issues/1450")
11491150
def test_nwb2asset_remote_asset(nwb_dandiset: SampleDandiset) -> None:
11501151
pytest.importorskip("fsspec")

0 commit comments

Comments
 (0)