[Bug] OpenAI embedder uses default httpx pool (max_connections=1000, keepalive_expiry=inf) — CLOSE_WAIT leak, search latency 15-60s
Environment
- OpenViking 0.4.7 (verified unfixed through 0.4.16 by source diff of all intermediate versions)
- Embedding backend: local llama.cpp
llama-server(OpenAI-compatible) on 127.0.0.1 - Deployment: OV as memory backend for a multi-agent setup, search under sustained load
Summary
OpenAIEmbedder._get_async_client() creates the OpenAI client with no httpx pool configuration:
# openviking/models/embedder/openai_embedders.py (identical in 0.4.7 and 0.4.16)
def _get_async_client(self):
return openai.AsyncOpenAI(**self._client_kwargs)
The OpenAI SDK defaults to httpx.Limits(max_connections=1000, keepalive_expiry=None) (unlimited keepalive). Against a local llama.cpp backend that closes idle connections, this produces:
- CLOSE_WAIT accumulation — connections pile up in CLOSE_WAIT on the OV side (observed hundreds under sustained search load)
- Search latency degradation 15-60s — pool checkout contends with dead connections being retried
Observed evidence (production)
viking_searchlatency 15-60s under load;ss -tan state close-wait | wc -lclimbing into the hundreds against the embedding server port- After injecting a bounded client, search latency dropped to <500ms and CLOSE_WAIT count went to ~0, stable for weeks
Fix that works here (workaround patch)
Inject a bounded httpx.AsyncClient before creating the OpenAI client:
import httpx
_limits = httpx.Limits(max_connections=2, max_keepalive_connections=1, keepalive_expiry=5)
_timeout = httpx.Timeout(connect=5.0, read=30.0, write=10.0, pool=30.0)
_http_client = httpx.AsyncClient(limits=_limits, timeout=_timeout)
return openai.AsyncOpenAI(http_client=_http_client, **self._client_kwargs)
Suggestion
Expose pool limits (max_connections / keepalive_expiry / timeouts) in the embedder config, or at minimum set sane non-default limits for local backends. Note the same bare-client pattern exists in the other embedders (dashscope_embedders.py, cohere_embedders.py, minimax_embedders.py, vikingdb_embedders.py use bare httpx.AsyncClient(timeout=60.0)).
I'd like to take this. I'll reproduce the OpenAI embedder client lifecycle against a controlled local HTTP server, then keep the fix scoped to bounded HTTP connection settings and correct async-client ownership. I'll add focused configuration, reuse, and cleanup coverage without changing embedding request or response semantics.