All case studies
Open Sourcedatabrickslabs/ontobricks · 2026

Stopping one slow question from freezing an app

Diagnosing and fixing an event-loop stall in a Databricks Labs project I don't maintain.

External contributor

The problem

In OntoBricks' Graph Chat, one broad question could freeze the entire application until it was redeployed. Not slow: frozen, for every user at once. That is the kind of bug that looks like an infrastructure problem and is actually an architecture problem.

What I did

Architecture

Before and after: a blocking graph read on the shared event loopBEFOREGraph ChatOther usersuvicorn event loopsingle-threadedGraph readunboundedwhole app frozenuntil redeployAFTERGraph ChatOther usersuvicorn event loopstays responsiveWorker poolauto-sizedBounded readclamped timeoutone request cancelledeveryone else unaffected
Before, a slow graph read executed directly on the single uvicorn event loop, so while it ran nothing else could, including health checks. After, blocking work runs on an auto-sized worker pool and every read carries a server-side bound, so an oversized query fails as one cancelled request instead of taking the process down.

What went wrong first

The reported symptom was not the bug

'Graph Chat is slow' pointed at query performance. Slowness was real but incidental. The reason it took the whole app down was that it ran on the shared event loop. Fixing only the query would have made the freeze rarer and no less total.

Bounds leak if you are careless with pools

Applying a statement timeout to a pooled connection silently affects the next borrower. Resetting it on release was a small change that prevented a class of bug that would have been very hard to attribute later.

Contributing to a codebase you don't own

This meant matching their conventions, their changelog format and their review expectations, and being explicit about what I could not verify locally: the toolchain would not fully install in my environment, so I stated exactly which subset I ran and left the rest to CI.

Results

PR #116, labelled 'status: in progress'
OpenPR #116, labelled 'status: in progress'
milestone the maintainers accepted it into
v0.7.0milestone the maintainers accepted it into
PRs opened to the project
4PRs opened to the project

Most production incidents are not exotic. They are a blocking call on a shared resource with no upper bound. Recognising that shape quickly, in a codebase you have never seen, is most of the job.

Stack

PythonFastAPIuvicornasyncioPostgreSQLDatabrickspytest
PR #116Project