aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-worker1.c-pp.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/wasm/api/sqlite3-api-worker1.c-pp.js')
-rw-r--r--ext/wasm/api/sqlite3-api-worker1.c-pp.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/ext/wasm/api/sqlite3-api-worker1.c-pp.js b/ext/wasm/api/sqlite3-api-worker1.c-pp.js
index 5e088f438..55ad16185 100644
--- a/ext/wasm/api/sqlite3-api-worker1.c-pp.js
+++ b/ext/wasm/api/sqlite3-api-worker1.c-pp.js
@@ -385,10 +385,19 @@ sqlite3.initWorker1API = function(){
const getDbId = function(db){
let id = wState.idMap.get(db);
if(id) return id;
- id = 'db#'+(++wState.idSeq)+'@'+db.pointer;
+ id = 'db#'+(++wState.idSeq)+':'+
+ Math.floor(Math.random() * 100000000)+':'+
+ Math.floor(Math.random() * 100000000);
/** ^^^ can't simply use db.pointer b/c closing/opening may re-use
the same address, which could map pending messages to a wrong
- instance. */
+ instance.
+
+ 2025-07: https://github.com/sqlite/sqlite-wasm/issues/113
+ demonstrates that two Worker1s can end up with the same IDs,
+ despite using different instances of the library, so we need
+ to add some randomness to the IDs instead of relying on the
+ pointer addresses.
+ */
wState.idMap.set(db, id);
return id;
};