diff options
author | stephan <stephan@noemail.net> | 2024-07-12 13:49:54 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2024-07-12 13:49:54 +0000 |
commit | be3778dee23d0df84d4c721ddd85f1c8975b67ac (patch) | |
tree | 3e6f214fea2ccf9ac5f2922f5c62b9081dcb20a1 /ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | |
parent | 74d5faec938ed149de77ce5de1e20d608806af93 (diff) | |
parent | 20ff50ad10145b5c6843c0a4da48138db3413260 (diff) | |
download | sqlite-be3778dee23d0df84d4c721ddd85f1c8975b67ac.tar.gz sqlite-be3778dee23d0df84d4c721ddd85f1c8975b67ac.zip |
Work around a difficult-to-trigger Atomics API message-passing quirk in the OPFS VFS which appears in rare instances in some browsers when running high I/O loads. This resolves [https://github.com/sqlite/sqlite-wasm/issues/12 | issue #12 of the npm distribution].
FossilOrigin-Name: af41a1e6fc8b36e9bf65a5bb0154e1ce7eb99903cb5a3e4779322527c29d8780
Diffstat (limited to 'ext/wasm/api/sqlite3-vfs-opfs.c-pp.js')
-rw-r--r-- | ext/wasm/api/sqlite3-vfs-opfs.c-pp.js | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js index fc0fb9db9..59a07aac7 100644 --- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js @@ -443,7 +443,7 @@ const installOpfsVfs = function callee(options){ OPFS_UNLINK_BEFORE_OPEN: 0x02, /** If true, any async routine which implicitly acquires a sync - access handle (i.e. an OPFS lock) will release that locks at + access handle (i.e. an OPFS lock) will release that lock at the end of the call which acquires it. If false, such "autolocks" are not released until the VFS is idle for some brief amount of time. @@ -470,9 +470,23 @@ const installOpfsVfs = function callee(options){ Atomics.notify(state.sabOPView, state.opIds.whichOp) /* async thread will take over here */; const t = performance.now(); - Atomics.wait(state.sabOPView, state.opIds.rc, -1) - /* When this wait() call returns, the async half will have - completed the operation and reported its results. */; + while('not-equal'!==Atomics.wait(state.sabOPView, state.opIds.rc, -1)){ + /* + The reason for this loop is burried in the details of + a long discussion at: + + https://github.com/sqlite/sqlite-wasm/issues/12 + + Summary: in at least one browser flavor, under high loads, + this wait() call can, on rare occasion, end up returning + 'ok', which indicates that it's returning _without_ the + other half of the proxy having called Atomics.notify(). When + this happens, we just wait() again. + */ + } + /* When the above wait() call returns 'not-equal', the async + half will have completed the operation and reported its results + in the state.opIds.rc slot of the SAB. */ const rc = Atomics.load(state.sabOPView, state.opIds.rc); metrics[op].wait += performance.now() - t; if(rc && state.asyncS11nExceptions){ |