Skip to content

Commit 824a6dc

Browse files
lesebclaude
andauthored
fix(vector_io): prevent duplicate libomp crash when importing faiss on macOS (#6304)
# What does this PR do? Fixes a fatal server crash (OMP Error #15) that occurs on macOS when faiss and another dependency (e.g. torch, scipy) each load their own copy of `libomp.dylib`. The fix sets `KMP_DUPLICATE_LIB_OK=TRUE` before importing faiss, scoped to macOS only via `sys.platform == "darwin"`, with a debug log for visibility. ## Test Plan 1. Run the server on macOS with faiss and another OpenMP-linked library installed 2. Trigger a vector store operation (e.g. `POST /v1/vector_stores`) that causes faiss to be loaded 3. Verify the server no longer crashes with `OMP: Error #15: Initializing libomp.dylib, but found libomp.dylib already initialized` 4. Check debug logs for `Set KMP_DUPLICATE_LIB_OK=TRUE to avoid duplicate libomp crash` Pre-commit checks all pass: ``` uv run pre-commit run --all-files # all passed ``` Signed-off-by: Sébastien Han <seb@redhat.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dc823bc commit 824a6dc

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • src/ogx/providers/inline/vector_io/faiss

src/ogx/providers/inline/vector_io/faiss/faiss.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import base64
99
import io
1010
import json
11+
import os
12+
import sys
1113
import threading
1214
from typing import TYPE_CHECKING, Any
1315

@@ -25,6 +27,12 @@ def _get_faiss() -> Any:
2527
with _faiss_lock:
2628
if _faiss is not None:
2729
return _faiss
30+
# faiss links against OpenMP; on macOS another dependency (e.g. torch,
31+
# scipy) may already have loaded libomp, causing a fatal duplicate-
32+
# runtime crash (OMP Error #15: "found libomp already initialized").
33+
if sys.platform == "darwin":
34+
os.environ.setdefault("KMP_DUPLICATE_LIB_OK", "TRUE")
35+
logger.debug("Set KMP_DUPLICATE_LIB_OK=TRUE to avoid duplicate libomp crash")
2836
import faiss # type: ignore[import-untyped]
2937

3038
_faiss = faiss

0 commit comments

Comments
 (0)