mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-24 20:34:05 +02:00
Gate yaak-web to wasm32 and make the DB lock cover every worker
CI runs `cargo test --all`, which compiled yaak-web for the host and failed in sqlite-wasm-rs's C shim. The crate is now `#![cfg(target_arch = "wasm32")]` with its browser-only dependencies target-scoped, so it is empty natively. Review caught a race in the worker fallback: a shared worker that starts after the tab has given up on it and taken a dedicated worker would open the database with no lock. The Web Lock now guards every worker, shared or not — requested with a short timeout so a reloading tab's dying predecessor is waited out, then reported. The tab also closes the port it abandoned. Verified in production builds: 8/8 shared and 3/3 dedicated reloads render, and a second tab in dedicated mode is told the database is in use.
This commit is contained in:
@@ -137,6 +137,12 @@ export class WorkerConnection {
|
||||
* only then gives up on sharing and takes a dedicated worker.
|
||||
*/
|
||||
private replaceWorker(why: string): void {
|
||||
// Let go of the port that never answered. If a slow shared worker does
|
||||
// come up later, it will find its port closed and — since it takes the
|
||||
// same lock the replacement takes — cannot open the database beneath us.
|
||||
if (this.port instanceof MessagePort) this.port.close();
|
||||
else this.port.terminate();
|
||||
|
||||
if (this.sharedAttempts < MAX_SHARED_ATTEMPTS) {
|
||||
console.warn(`Reconnecting to the database worker (${why})`);
|
||||
this.port = this.connectShared();
|
||||
|
||||
Reference in New Issue
Block a user