Skip to content

Commit acd655c

Browse files
committed
fix: resolve Promise.all concurrent query collision with identical SQL strings
1 parent 639a330 commit acd655c

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/17alasql.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,11 @@ function cleanupCache(statement) {
261261
if (!alasql.options.cache) {
262262
return;
263263
}
264-
// cleanup the table data to prevent storing this information in the SQL cache
265-
if (statement && statement.query && statement.query.data) {
266-
statement.query.data = [];
267-
}
264+
// NOTE: Do NOT mutate statement.query.data on the cached statement object.
265+
// The compiled statement is shared across concurrent executions via sqlCache.
266+
// Mutating it here clears data that another concurrent Promise.all call
267+
// may still be reading, causing empty results with no error thrown.
268+
// See: https://github.com/AlaSQL/alasql/issues/1953
268269
}
269270

270271
/**
@@ -284,7 +285,9 @@ alasql.dexec = function (databaseid, sql, params, cb, scope) {
284285
let statement = db.sqlCache[hh];
285286
// If database structure was not changed since last time return cache
286287
if (statement && db.dbversion === statement.dbversion) {
287-
var res = statement(params, cb);
288+
// Clone params to prevent concurrent executions from sharing
289+
// the same params reference when called via Promise.all
290+
var res = statement(Array.isArray(params) ? params.slice() : Object.assign({}, params), cb);
288291
cleanupCache(statement);
289292
return res;
290293
}

0 commit comments

Comments
 (0)