mirror of
https://github.com/allankoechke/turso.git
synced 2026-11-30 11:12:58 +00:00
A yield carries no pending I/O completion by design: core deliberately does not store yields in io_completions, so no completion callback will ever fire for one. The JS binding folded Yield into STEP_IO, and the wasm driver handles STEP_IO by awaiting an I/O notification from the OPFS worker. When a statement yielded while no I/O was in flight, nothing ever notified the waiter, so the statement (and everything queued behind the connection's exec lock) hung forever in the browser. Node was unaffected only because its ioStep is a no-op. Map Yield to STEP_SLEEP with a 1ms delay so the step loops re-step on a timer instead of waiting for a notification that was never scheduled. This mirrors the STEP_SLEEP approach from #8325 for busy_timeout and needs no driver changes: both the native and wasm step loops already handle STEP_SLEEP by sleeping and stepping again, which matches core's contract that a yielded instruction simply re-executes on the next step. No regression test: per review, an injection-based test was rejected and the bug cannot be reproduced from pure JavaScript. Every natural yield source in core (btree cursor-restore TryAdvance, materialized view populate, pager init lock, in-flight page reads, MVCC allocator contention) needs async I/O in flight or cross-connection thread contention, neither of which single-threaded JS can trigger through the native binding, whose PlatformIO completes I/O synchronously. Tests: cd bindings/javascript && yarn install && yarn workspace @tursodatabase/database-common build && yarn workspace @tursodatabase/database exec napi build --platform --esm --manifest-path ../../Cargo.toml --output-dir . && yarn workspace @tursodatabase/database run test && git checkout -- packages/native/index.js packages/native/index.d.ts Fixes #8341