From 4c848dd60e97365a137ede6a63028662cd9b75af Mon Sep 17 00:00:00 2001 From: George Panchuk Date: Fri, 25 Sep 2026 03:34:46 +0700 Subject: [PATCH] fix: time out model_info so a silent hf endpoint can't hang download_model --- fastembed/common/model_management.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fastembed/common/model_management.py b/fastembed/common/model_management.py index 5a27923c..5974535e 100644 --- a/fastembed/common/model_management.py +++ b/fastembed/common/model_management.py @@ -12,7 +12,7 @@ from typing import Any, TypeVar, Generic import requests -from huggingface_hub import snapshot_download, model_info, list_repo_tree +from huggingface_hub import constants, snapshot_download, model_info, list_repo_tree from huggingface_hub.hf_api import RepoFile from huggingface_hub.utils import ( RepositoryNotFoundError, @@ -259,7 +259,11 @@ def _save_file_metadata(model_dir: Path, meta: dict[str, dict[str, int | str]]) ) return result - repo_revision = model_info(hf_source_repo).sha + # hub sends this request with no timeout unless given one, so an endpoint that accepts + # the connection but never answers would block here for good, before download_model can + # retry or fall back to another source. list_repo_tree and snapshot_download's own + # metadata requests can't be given one, but a silent endpoint now fails here first. + repo_revision = model_info(hf_source_repo, timeout=constants.HF_HUB_ETAG_TIMEOUT).sha repo_tree = list(list_repo_tree(hf_source_repo, revision=repo_revision, repo_type="model")) allowed_extensions = {".json", ".onnx", ".txt"}