https://www.boundaryml.com logo
Reading Collector.last during an in-flight call pa...
# help
l
If another thread reads collector.last.timing while a call using that collector is starting, the read panics with Function log expected to be present (no FunctionStart event?). The panic happens while BAML_TRACER is locked, which poisons the mutex. From then on, every BAML call in the process fails with PoisonError / RustPanic: rust future panicked. Locally the process aborts (“panic in a destructor during cleanup”). In production it stayed up, but every call failed for up to ~25 minutes, until the worker was recycled.
Versions baml-py 0.223.0 and 0.226.3: both reproduce it, 3/3 runs each, within about 1 s Python 3.11. Repro on macOS arm64; production on Linux (Cloud Run), gunicorn + uvicorn Cause (from the source) In BamlTracer::start_call (tracing/mod.rs), collector.track_function(call_id) runs before the FunctionStart event is put into BAML_TRACER. Between those two steps, collector.last returns a FunctionLog for that ID. Its getters call get_inner, and build_function_log returns None because there are no events yet. The code then does: let tracer = BAML_TRACER.lock().unwrap(); build_function_log(&tracer, &self.id) .expect("Function log expected to be present (no FunctionStart event?) ...") // panics with the lock held That poisons the mutex, and every later BAML_TRACER.lock().unwrap() panics: tracing/mod.rs:484, lib.rs:378, storage.rs:594/723 and primitive/request.rs:144.
Repro: 32 concurrent async calls against a local fake OpenAI-compatible server, each with its own Collector, while another thread polls the newest collectors’ .last.timing. It panics within about 1 s, 3/3 runs on both versions. Without the polling thread, 16k calls run clean. Large call arguments (~2 MB, like images) widen the gap a lot, because the arguments are serialized into the start event between those two steps. Suggested fixes: Return None instead of panicking in get_inner, or at least don’t panic while holding the lock. Record FunctionStart before track_function. Recover from a poisoned lock instead of calling .unwrap().
v
cc @aaronv (BAML)
a
will take a look!