From 16f51b3e70d6711127103718e3ed2a0829b3dacb Mon Sep 17 00:00:00 2001 From: Youngbeom Choi Date: Tue, 24 Nov 2026 15:06:10 +0900 Subject: [PATCH 1/2] fix: Keep refreshing the registry after a failed periodic refresh The feature server scheduled the next registry refresh only after the current one succeeded. A single transient error from the registry backend (for example an SSL error while downloading an S3 registry) ended the timer thread, and the worker kept serving its cached registry without refreshing it again until restart. Catch and log errors in the periodic refresh and always schedule the next attempt. The first refresh still runs in the app lifespan and fails startup on error, as before. Scheduling a timer and stopping refreshes at shutdown now hold the same lock. Before, shutdown could cancel the previous timer while a refresh was scheduling the next one, and the new timer then kept the process waiting for one more interval. Signed-off-by: Youngbeom Choi --- sdk/python/feast/feature_server.py | 40 ++++++--- sdk/python/tests/unit/test_feature_server.py | 92 ++++++++++++++++++++ 2 files changed, 120 insertions(+), 12 deletions(-) diff --git a/sdk/python/feast/feature_server.py b/sdk/python/feast/feature_server.py index e963ade846e..42e808f1a09 100644 --- a/sdk/python/feast/feature_server.py +++ b/sdk/python/feast/feature_server.py @@ -539,6 +539,7 @@ def get_app( # Asynchronously refresh registry, notifying shutdown and canceling the active timer if the app is shutting down shutting_down = False active_timer: Optional[threading.Timer] = None + refresh_timer_lock = threading.Lock() # --- Offline write batching config and batcher --- fs_cfg = getattr(store.config, "feature_server", None) batching_cfg = None @@ -593,23 +594,36 @@ def get_app( def stop_refresh(): nonlocal shutting_down - shutting_down = True - if active_timer: - active_timer.cancel() + with refresh_timer_lock: + shutting_down = True + if active_timer: + active_timer.cancel() vs_registry = VectorStoreRegistry(store) - def async_refresh(): - if shutting_down: - return - + def refresh_registry_caches() -> None: store.refresh_registry() vs_registry.refresh() - if registry_ttl_sec: - nonlocal active_timer - active_timer = threading.Timer(registry_ttl_sec, async_refresh) - active_timer.start() + def schedule_refresh() -> None: + nonlocal active_timer + with refresh_timer_lock: + if registry_ttl_sec and not shutting_down: + active_timer = threading.Timer(registry_ttl_sec, periodic_refresh) + active_timer.start() + + def periodic_refresh() -> None: + if shutting_down: + return + + try: + refresh_registry_caches() + except Exception: + # Non-fatal error - the cached registry keeps serving + logger.exception( + "Registry refresh failed; retrying in %s seconds", registry_ttl_sec + ) + schedule_refresh() # --- Audit logging setup --- audit_logging_cfg = getattr(fs_cfg, "audit_logging", None) @@ -633,7 +647,9 @@ async def lifespan(app: FastAPI): app.state.audit_logger = audit_logger_instance await store.initialize() - async_refresh() + # Unlike periodic refreshes, a failure here fails startup + refresh_registry_caches() + schedule_refresh() try: yield finally: diff --git a/sdk/python/tests/unit/test_feature_server.py b/sdk/python/tests/unit/test_feature_server.py index 593973da8c2..df6fe1fe807 100644 --- a/sdk/python/tests/unit/test_feature_server.py +++ b/sdk/python/tests/unit/test_feature_server.py @@ -13,6 +13,7 @@ # limitations under the License. import json import sys +import threading import time from collections import Counter from datetime import timedelta @@ -899,3 +900,94 @@ def test_get_online_features_serves_non_finite_float(store_and_client, non_finit assert body["results"][ix]["values"] == [ "Infinity" if non_finite > 0 else "-Infinity" ] + + +@pytest.fixture +def push_store(tmp_path): + store = _build_push_feature_store(tmp_path) + try: + yield store + finally: + store.teardown() + + +@pytest.fixture +def mock_timer(): + """Captures registry refresh timers so a test can fire them by hand.""" + with patch("feast.feature_server.threading.Timer") as mock_timer: + yield mock_timer + + +def _fire_scheduled_refresh(mock_timer): + mock_timer.call_args.args[1]() + + +def test_periodic_registry_refresh_keeps_running_after_a_failure( + push_store, mock_timer, caplog +): + """A failed periodic refresh must not stop later refreshes.""" + with ( + patch.object( + push_store, + "refresh_registry", + side_effect=[None, RuntimeError("transient registry error"), None], + ) as refresh_registry, + TestClient(get_app(push_store, registry_ttl_sec=60)), + ): + assert mock_timer.call_count == 1 + + _fire_scheduled_refresh(mock_timer) + + assert mock_timer.call_count == 2 + assert mock_timer.call_args.args[0] == 60 + assert "transient registry error" in caplog.text + + _fire_scheduled_refresh(mock_timer) + + assert refresh_registry.call_count == 3 + assert mock_timer.call_count == 3 + + +def test_registry_refresh_failure_at_startup_still_fails_startup( + push_store, mock_timer +): + """A failed first refresh must fail app startup.""" + with ( + patch.object( + push_store, + "refresh_registry", + side_effect=RuntimeError("registry unavailable"), + ), + pytest.raises(RuntimeError, match="registry unavailable"), + ): + with TestClient(get_app(push_store, registry_ttl_sec=60)): + pass + + mock_timer.assert_not_called() + + +def test_registry_refresh_timer_scheduled_during_shutdown_is_cancelled( + push_store, mock_timer +): + """Shutdown must cancel a refresh timer that is scheduled while it runs.""" + scheduling = threading.Event() + timers = [] + + def make_timer(*args, **kwargs): + timer = MagicMock() + timers.append(timer) + if len(timers) == 2: + scheduling.set() + # Hold the scheduling step open while the app shuts down + time.sleep(0.5) + return timer + + mock_timer.side_effect = make_timer + with TestClient(get_app(push_store, registry_ttl_sec=60)): + refresh = threading.Thread(target=_fire_scheduled_refresh, args=(mock_timer,)) + refresh.start() + assert scheduling.wait(timeout=5) + refresh.join() + + assert len(timers) == 2 + timers[1].cancel.assert_called_once() From b017f330d4edc85162ba36d71e68ed40239759da Mon Sep 17 00:00:00 2001 From: Youngbeom Choi Date: Tue, 24 Nov 2026 16:44:10 +0900 Subject: [PATCH 2/2] test: Annotate the new registry refresh tests Signed-off-by: Youngbeom Choi --- sdk/python/tests/unit/test_feature_server.py | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sdk/python/tests/unit/test_feature_server.py b/sdk/python/tests/unit/test_feature_server.py index df6fe1fe807..f5ae837a763 100644 --- a/sdk/python/tests/unit/test_feature_server.py +++ b/sdk/python/tests/unit/test_feature_server.py @@ -17,7 +17,9 @@ import time from collections import Counter from datetime import timedelta +from pathlib import Path from types import SimpleNamespace +from typing import Any, Generator from unittest.mock import AsyncMock, MagicMock, patch import pytest @@ -903,7 +905,7 @@ def test_get_online_features_serves_non_finite_float(store_and_client, non_finit @pytest.fixture -def push_store(tmp_path): +def push_store(tmp_path: Path) -> Generator[FeatureStore, None, None]: store = _build_push_feature_store(tmp_path) try: yield store @@ -912,19 +914,19 @@ def push_store(tmp_path): @pytest.fixture -def mock_timer(): +def mock_timer() -> Generator[MagicMock, None, None]: """Captures registry refresh timers so a test can fire them by hand.""" with patch("feast.feature_server.threading.Timer") as mock_timer: yield mock_timer -def _fire_scheduled_refresh(mock_timer): +def _fire_scheduled_refresh(mock_timer: MagicMock) -> None: mock_timer.call_args.args[1]() def test_periodic_registry_refresh_keeps_running_after_a_failure( - push_store, mock_timer, caplog -): + push_store: FeatureStore, mock_timer: MagicMock, caplog: pytest.LogCaptureFixture +) -> None: """A failed periodic refresh must not stop later refreshes.""" with ( patch.object( @@ -949,8 +951,8 @@ def test_periodic_registry_refresh_keeps_running_after_a_failure( def test_registry_refresh_failure_at_startup_still_fails_startup( - push_store, mock_timer -): + push_store: FeatureStore, mock_timer: MagicMock +) -> None: """A failed first refresh must fail app startup.""" with ( patch.object( @@ -967,13 +969,13 @@ def test_registry_refresh_failure_at_startup_still_fails_startup( def test_registry_refresh_timer_scheduled_during_shutdown_is_cancelled( - push_store, mock_timer -): + push_store: FeatureStore, mock_timer: MagicMock +) -> None: """Shutdown must cancel a refresh timer that is scheduled while it runs.""" scheduling = threading.Event() - timers = [] + timers: list[MagicMock] = [] - def make_timer(*args, **kwargs): + def make_timer(*args: Any, **kwargs: Any) -> MagicMock: timer = MagicMock() timers.append(timer) if len(timers) == 2: