Repository navigation
fix: resolve Promise.all concurrent query collision with identical SQ… - #2465
Conversation
|
Ohhh, very nice. Please make a file named |
mathiasrw
left a comment
There was a problem hiding this comment.
Please provide a test file named test/test1953.js that fails with the original code and that does not failed with the modified code.
mathiasrw
left a comment
There was a problem hiding this comment.
We need a test file that fails before the merge and passes after the merge.
|
@imsanupm are you still on this? |
|
Thank you @imsanupm for opening this and for tracking down where the collision happens. We kept your PR and pushed two commits to it, so it can be merged with you as the author:
Why the change: keeping
Closes #1953. |
Description
Fixes #1953
When two async functions with identical SQL strings were executed
concurrently via
Promise.all, no results were returned and no errorwas thrown.
Root Cause
Two separate issues were working together to cause this bug:
cleanupCachemutating shared cached object — The compiledstatement stored in
sqlCacheis shared across concurrent executions.cleanupCachewas clearingstatement.query.data = []on this sharedobject while another concurrent call was still reading it, silently
wiping the results.
Shared params reference — Concurrent executions via
Promise.allwere sharing the same params reference, allowing one call to overwrite
another's parameters (
f1/f2).Why it was hard to notice
fine because they got different cache keys
Promise.allChanges
cleanupCache()— Removed mutation ofstatement.query.dataon theshared cached statement object
alasql.dexec()— Clone params before passing to cached statementexecution to isolate each concurrent call's parameters
How to reproduce (before fix)
Testing
Promise.allnow return correct resultsalasql.options.cache = false) unaffected