Skip to content

fix: resolve Promise.all concurrent query collision with identical SQ…#2465

Open
imsanupm wants to merge 1 commit intoAlaSQL:developfrom
imsanupm:develop
Open

fix: resolve Promise.all concurrent query collision with identical SQ…#2465
imsanupm wants to merge 1 commit intoAlaSQL:developfrom
imsanupm:develop

Conversation

@imsanupm
Copy link
Copy Markdown

@imsanupm imsanupm commented Apr 8, 2026

Description

Fixes #1953

When two async functions with identical SQL strings were executed
concurrently via Promise.all, no results were returned and no error
was thrown.

Root Cause

Two separate issues were working together to cause this bug:

  1. cleanupCache mutating shared cached object — The compiled
    statement stored in sqlCache is shared across concurrent executions.
    cleanupCache was clearing statement.query.data = [] on this shared
    object while another concurrent call was still reading it, silently
    wiping the results.

  2. Shared params reference — Concurrent executions via Promise.all
    were sharing the same params reference, allowing one call to overwrite
    another's parameters (f1/f2).

Why it was hard to notice

  • Running functions individually worked fine
  • Running with different SQL strings (different LIMIT values) worked
    fine because they got different cache keys
  • No error was thrown — results were just silently empty
  • Only triggered by concurrent identical SQL strings via Promise.all

Changes

  • cleanupCache() — Removed mutation of statement.query.data on the
    shared cached statement object
  • alasql.dexec() — Clone params before passing to cached statement
    execution to isolate each concurrent call's parameters

How to reproduce (before fix)

async function fun1() {
    return await alasql.promise(`select * from xlsx(?)`, ["D:\\a1.xlsx"]);
}
async function fun2() {
    return await alasql.promise(`select * from xlsx(?)`, ["D:\\a2.xlsx"]);
}

// Returns empty, no error thrown
const results = await Promise.all([fun1(), fun2()]);

Testing

  • Identical SQL strings in Promise.all now return correct results
  • Different SQL strings still work as before
  • Sequential (non-concurrent) queries unaffected
  • Queries without cache (alasql.options.cache = false) unaffected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Promise.all error

1 participant