Import deadlock in openviking.server.bootstrap on Windows — __getattr__ lazy loading + recursive import lock
title: Import deadlock in openviking.server.bootstrap on Windows — getattr lazy loading + recursive import lock labels: bug, windows assignees: ''
Description
import openviking.server.bootstrap (and transitively openviking.service.core) deadlocks on Windows. The root cause is a recursive import lock triggered by the getattr lazy-loading mechanism in openviking/storage/init.py combined with eager top-level imports in openviking/service/core.py.
Environment
- OS: Windows 11
- Python: 3.12.5
- openviking: 0.4.11 (pip installed)
- Reproducer: python -c "import openviking.server.bootstrap" hangs indefinitely
Root Cause
The deadlock chain is:
- openviking.service.core does a top-level rom openviking.storage import VikingDBManager (line ~24)
- openviking.storage.getattr("VikingDBManager") is triggered (since VikingDBManager is lazy-loaded via _LAZY_IMPORTS)
- getattr calls importlib.import_module("openviking.storage.vikingdb_manager")
- ikingdb_manager.py (module-level) does rom openviking.storage.queuefs.embedding_msg import EmbeddingMsg
- This triggers another import openviking.storage → Python finds it already partially initialized in sys.modules → tries getattr("queuefs") → importlib.import_module("openviking.storage.queuefs") → import lock contention with step 1
The core issue: openviking/storage/init.py uses getattr + _LAZY_IMPORTS to defer sub-module loading. However, this deferred loading happens during another openviking.service.core import that already holds the import lock for openviking.storage. When the lazily-loaded sub-module tries to import sibling sub-modules of openviking.storage, it attempts to acquire the same import lock, causing a deadlock.
Additional Hanging Modules
Further tracing shows even direct imports of certain sub-modules also deadlock:
- import openviking.storage.content_write — hangs (imports openviking.storage.queuefs.queue_processor which deadlocks)
- import openviking.service.fs_service — hangs
- import openviking.service.debug_service — hangs
Minimal Reproducer
`python
hangs indefinitely:
import openviking.storage.content_write `
Even with sentence_transformers and orch uninstalled (to rule out those known Windows issues), the deadlock persists.
Suggestion
Consider replacing the getattr-based lazy loading with explicit eager imports for the sub-modules that are most commonly imported by service modules. Specifically, adding these to storage/init.py would break the circular import chain:
python from openviking.storage.vikingdb_manager import VikingDBManager, VikingDBManagerProxy from openviking.storage.queuefs import QueueManager, get_queue_manager, init_queue_manager from openviking.storage.viking_fs import VikingFS, get_viking_fs, init_viking_fs
This mirrors the approach used for openviking.storage.errors (which is already eagerly imported in storage/init.py).
Alternatively, a safer lazy-loading mechanism that doesn't rely on importlib.import_module() re-entering the parent package's import lock.
Thanks — I checked the current import chain, and the deadlock-relevant structure described in this issue is still present.
In the current tree:
openviking.service.corestill importsVikingDBManagerfromopenviking.storageat module top levelopenviking.storage.__init__still resolves that symbol through__getattr__+_LAZY_IMPORTSopenviking.storage.vikingdb_managerstill importsopenviking.storage.queuefs.*during module import
So the effective sequence is still:
- import
openviking.service.core - trigger
openviking.storage.__getattr__("VikingDBManager") - import
openviking.storage.vikingdb_manager - re-enter sibling imports under
openviking.storagewhile the parent package is only partially initialized
That means the recursive import shape reported here has not been structurally eliminated.
To be precise, I have not re-run a fresh Windows reproduction on current HEAD, so I am not claiming a newly confirmed runtime hang. But based on the current code, this issue should not be considered fixed at the import-structure level.
The cleanest fix would be to break this path entirely, either by importing VikingDBManager directly from openviking.storage.vikingdb_manager in core.py, or by eagerly exporting the commonly used runtime symbols from openviking.storage.__init__ instead of resolving them lazily through __getattr__.