https://www.boundaryml.com logo
🟡 Memory issues (SIGFAULT 139 code) with BAML ver...
# questions
a
Hi, did anyone getting memory issues (SIGFAULT 139 code) when using BAML? I get it time to time and using 0.203.1 version
v
Could you outline what you are doing by chance?
Haven’t seen that one before
Does it happen during execution or while writing code?
a
Sure, I use baml async client in my fastapi application and when request comes (this is the SSE streaming application) I start and try to yield chunks with baml like that:
Copy code
async def get_structured_answer_stream(
    prompt: str, language: str, kb: KnowledgeBase, answer_found: List[bool] = None
):
    def _get_baml_client():
        return import_module("app.core.baml.baml_client.async_client").b

    # Try Anthropic first
    try:
        print(
            f"[SEGFAULT_DEBUG] Step 4-init: Creating Anthropic stream | Q: (passed in prompt)'",
            flush=True,
        )
        stream = _get_baml_client().stream.ExtractChatAnswerAnthropic(prompt)
        print(
            f"[SEGFAULT_DEBUG] Step 4-stream: Anthropic stream created, starting iteration | Q: (passed in prompt)'",
            flush=True,
        )
        async for result in _process_chat_stream(
            stream, "Anthropic", language, kb, answer_found
        ):
            yield result
        return
    except Exception as e:
        logger.error(f"ExtractChatAnswerAnthropic failed: {e}")
        logger.info("Falling back to ExtractChatAnswerGPT5")
However sometimes I see segfaul 139 when I get : [SEGFAULT_DEBUG] Step 4-init: Creating Anthropic stream | Q: (passed in prompt) So that is why I am suspecting BAML
What the logs show The [SEGFAULT_DEBUG] Step 4-init … Step 4a … prints come from get_structured_answer_stream in app/services/helper.py. That function immediately calls the BAML streaming client for Anthropic: When the Gunicorn worker later exits with code 139, that means the process received SIGSEGV. Because the crash happens inside that try block before we hit the except that logs “falling back to GPT5”, the only native code running is BAML’s stream client (baml_py + its Rust/C glue) while it manages the Anthropic connection. Nothing in our pure-Python layer manipulates pointers; when a worker segfaults here it’s almost always the native dependency (BAML runtime or one of its libs). So yes—this particular path strongly implicates the BAML layer handling ExtractChatAnswerAnthropic.
v
Perfect. Thanks for the code snippet! We can try and reproduce this on our end. I haven’t tried lazy importing of baml_client so I wonder if it’s related to that
a
How come you lazily import baml client?
a
I didnt initially but decided to try to see if that might be an issue
v
i see. were you able to get the source code btw? would make reproing this much easier!