Reformulate the forceReinitIfFailed handling based on feedback, to correct the type-checking and resolve a potential race condition.

FossilOrigin-Name: c4f468309158f9b951137461213fb269d96d15c331256cf392a56c9bed231460
This commit is contained in:
stephan 2024-07-11 19:50:17 +00:00
parent 9958c51a5d
commit 8ee747dda5
4 changed files with 22 additions and 17 deletions

View File

@ -1225,13 +1225,19 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
throw options.$testThrowPhase1;
}
if(initPromises[vfsName]){
const p = initPromises[vfsName];
if( (p instanceof OpfsSAHPool) || !options.forceReinitIfFailed ){
//log("Returning cached installOpfsSAHPoolVfs() result",options,vfsName,initPromises[vfsName]);
try {
const p = await initPromises[vfsName];
//log("installOpfsSAHPoolVfs() returning cached result",options,vfsName,p);
return p;
}catch(e){
//log("installOpfsSAHPoolVfs() got cached failure",options,vfsName,e);
if( options.forceReinitIfFailed ){
delete initPromises[vfsName];
/* Fall through and try again. */
}else{
throw e;
}
}
delete initPromises[vfsName];
/* Fall through and try again. */
}
if(!globalThis.FileSystemHandle ||
!globalThis.FileSystemDirectoryHandle ||

View File

@ -3193,11 +3193,13 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
/* Ensure that the forceReinitIfFailed fallback bypasses the VFS init cache... */
cErr = u3 = undefined;
conf2.forceReinitIfFailed = true;
conf2.verbosity = 3;
const P3b = await inst(conf2).then(u=>u3 = u).catch((e)=>cErr=e);
T.assert(undefined === cErr)
.assert(P3b === u3)
.assert(P3b === await inst(conf2))
.assert(true === await u3.removeVfs())
.assert(false === await u3.removeVfs());
.assert(false === await P3b.removeVfs());
}
}/*OPFS SAH Pool sanity checks*/)

View File

@ -1,5 +1,5 @@
C Add\san\soption\sto\sforce\sthe\sopfs-sahpool\sVFS\sinit\sto\sre-run\safter\sit\sfails\son\sa\sfirst\sattempt,\sas\sa\sworkaround\sfor\sflaky\senvironments\swhere\sinitial\saccess\sto\sOPFS\ssync\saccess\shandles\sis\srejected\sbut\sthen\spermitted\son\sa\ssecond\sattempt.\sReported\sand\sdiscussed\sin\s[https://github.com/sqlite/sqlite-wasm/issues/79|issue\s#79\sof\sthe\snpm\sdistribution].
D 2024-07-11T11:04:17.881
C Reformulate\sthe\sforceReinitIfFailed\shandling\sbased\son\sfeedback,\sto\scorrect\sthe\stype-checking\sand\sresolve\sa\spotential\srace\scondition.
D 2024-07-11T19:50:17.794
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -618,7 +618,7 @@ F ext/wasm/api/sqlite3-api-worker1.c-pp.js 5cc22a3c0d52828cb32aad8691488719f47d2
F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89
F ext/wasm/api/sqlite3-opfs-async-proxy.js 881af4643f037b6590c491cef5fac8bcdd4118993197a1fa222ccb8b01e3504a
F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d
F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js ddfe875d5fe84338fe0e8369c3d48015dd62b5bf706cfbd60ab71da6ac7a5dc9
F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js e7b8c70c9a239eee2b571b5cd60e2a1d677312b83ad7e6395629c2954d0f26d3
F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 0c3801a8e252944fdbaddbad698534316fde90d3db5eedae156e7774ab127710
F ext/wasm/api/sqlite3-vtab-helper.c-pp.js a2fcbc3fecdd0eea229283584ebc122f29d98194083675dbe5cb2cf3a17fe309
F ext/wasm/api/sqlite3-wasm.c 9267174b9b0591b4f71193542ab57adf95bb9415f7d3453acf4a8ca8052f5e6c
@ -667,7 +667,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c
F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c
F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2
F ext/wasm/tester1.c-pp.js e680b03be25fe65abf4e69c63a9037eba0ff0e26f0c322bd6d3e6221883f2ace
F ext/wasm/tester1.c-pp.js e231a9ae8b5ad6c3697339178e2e801edfb13cedcbd4a1e98bc5915646cc357d
F ext/wasm/tests/opfs/concurrency/index.html 0802373d57034d51835ff6041cda438c7a982deea6079efd98098d3e42fbcbc1
F ext/wasm/tests/opfs/concurrency/test.js a98016113eaf71e81ddbf71655aa29b0fed9a8b79a3cdd3620d1658eb1cc9a5d
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
@ -2195,11 +2195,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P bcef3f71a2f68768819d9f716f2c29e752fb173df1506469c8669d95ecc2ff50
R 363618acc9527dfc44058e319871c4df
T *branch * sahpool-reinit-fallback
T *sym-sahpool-reinit-fallback *
T -sym-trunk * Cancelled\sby\sbranch.
P 5286e0f654d91a4ebee51fcabaab696e17ff07bb18990b401a31bd3d1213e695
R 1edb9efa72844191061bd673c33c8081
U stephan
Z a0a1183624d3cfcdd58bad41e9c9ff1e
Z fea5c63c4f659006bc6ce3b8cbda987f
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
5286e0f654d91a4ebee51fcabaab696e17ff07bb18990b401a31bd3d1213e695
c4f468309158f9b951137461213fb269d96d15c331256cf392a56c9bed231460