context-mode icon indicating copy to clipboard operation
context-mode copied to clipboard

better-sqlite3 synchronous calls block the Node.js event loop

Open ofrik opened this issue 6 months ago • 0 comments

better-sqlite3 is a synchronous SQLite driver. All database operations — indexing, search, snapshot writes, event inserts — run on the Node.js event loop thread and block all other async I/O for their duration.

Under load (e.g. indexing a large document while ctx_execute is in progress), SQLite operations can starve pending tool responses.

Suggested fix: Offload all better-sqlite3 calls to a worker thread using worker_threads or a dedicated DB worker pool, so the event loop stays free for MCP I/O.

Alternatively, evaluate node:sqlite (Node 22.5+) or @databases/sqlite which offer async-friendly APIs.

Impact: Under concurrent tool calls, synchronous DB operations introduce latency spikes and can make the MCP server appear unresponsive.

ofrik avatar May 23 '26 00:05 ofrik