pub fn blocking_section<T>(f: impl FnOnce() -> T) -> TExpand description
Run a synchronous Store call from async code without stalling the
runtime (#590).
Every Store method does blocking filesystem I/O: write can poll the
advisory lock for up to 5 s (LOCK_TIMEOUT, std::thread::sleep in
50 ms steps) and then fsyncs, which on a Dropbox / OneDrive / SMB store
root costs hundreds of milliseconds uncontended. Called directly from an
async fn, that holds a tokio worker for the whole duration, delaying
every other task on it – including the rate limiter’s timers and other
in-flight MCP tool calls.
On a multi-thread runtime (#[tokio::main], doiget serve) this runs
f under [tokio::task::block_in_place], which hands the worker’s other
tasks to another thread first. Elsewhere – no runtime, or a
current-thread runtime, where block_in_place would panic – f runs
inline, as before.
block_in_place rather than spawn_blocking because the orchestrator
holds the store as &dyn Store (docs/PUBLIC_API.md §2): moving it into
a 'static closure would change the public signature of fetch_paper,
which is the cost the issue ruled out for making the trait async.