Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix timeout errors for big downloads from http #925

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lamindb_setup/core/_hub_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ def _delete_instance(
)
if require_empty:
for storage_record in storage_records:
root_string: str = storage_record["root"] # type: ignore
account_for_sqlite_file = (
instance_with_storage["db_scheme"] is None
and instance_with_storage["storage"]["root"] == storage_record["root"]
and instance_with_storage["storage"]["root"] == root_string
)
root_string = storage_record["root"]
# gate storage and instance deletion on empty storage location for
# normally auth.get_session() doesn't have access_token
# so this block is useless i think (Sergei)
Expand Down
28 changes: 21 additions & 7 deletions lamindb_setup/core/upath.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import fsspec
from lamin_utils import logger
from upath import UPath
from upath.implementations.cloud import CloudPath, S3Path # keep CloudPath!
from upath.implementations.cloud import CloudPath # keep CloudPath!
from upath.implementations.local import LocalPath

from ._aws_credentials import HOSTED_BUCKETS, get_aws_credentials_manager
Expand Down Expand Up @@ -738,12 +738,26 @@ def to_url(upath):
)


def create_path(path: UPath, access_token: str | None = None) -> UPath:
path = UPath(path)
# test whether we have an AWS S3 path
if not isinstance(path, S3Path):
return path
return get_aws_credentials_manager().enrich_path(path, access_token)
def create_path(path: UPathStr, access_token: str | None = None) -> UPath:
upath = UPath(path)

if upath.protocol == "s3":
# add managed credentials and other options for AWS s3 paths
return get_aws_credentials_manager().enrich_path(upath, access_token)

if upath.protocol in {"http", "https"}:
# this is needed because by default aiohttp drops a connection after 5 min
# so it is impossible to download large files
client_kwargs = upath.storage_options.get("client_kwargs", {})
if "timeout" not in client_kwargs:
from aiohttp import ClientTimeout

client_kwargs = {
**client_kwargs,
"timeout": ClientTimeout(sock_connect=30, sock_read=30),
}
return UPath(upath, client_kwargs=client_kwargs)
return upath


def get_stat_file_cloud(stat: dict) -> tuple[int, str | None, str | None]:
Expand Down
Loading