Repository navigation
fix(scan): throw when the scan result does not fit in memory - #184
Closed
pyramation wants to merge 1 commit into
Closed
pyramation wants to merge 1 commit into
pyramation wants to merge 1 commit into
Conversation
…of returning no tokens
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
This PR makes
Reviewed commit: fbd8177 |
|
Closing in favor of #183, which consolidates the v18 scan/fingerprint/normalize error-handling fixes (including the scan out-of-memory → empty tokens case found here). This PR's repro is being ported there as a regression test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scan()/scanSync()returned{ version: 0, tokens: [] }with no error when the JSON result could not be allocated. Large inputs therefore looked like empty SQL. Example:'SELECT 1;\n'.repeat(2_000_000)(20 MB, 6M tokens) givestokens.length === 0on 18.2.1 (and 18.2.0), whileparse()handles the same input without trouble.The cause is
build_scan_json. It pre-sizes the buffer at about 200 bytes per token, so the buffer passes the 1 GiB WASM cap at roughly 5M tokens. Whenmallocfailed, the function returned an empty JSON literal. A failed malloc for a single token's text was also skipped withcontinue, which silently dropped that token.Now any of those allocation failures makes
build_scan_jsonreturnNULL, andwasm_scanreturns"ERROR: out of memory building the scan result". The existing JS checkstartsWith('ERROR')turns that into a thrownError. The module stays usable after the throw.Regression test added to
versions/18/test/scan.test.js:An 8.8 MB real-world file (830k tokens) scans to byte-identical JSON before and after the change.
Link to Devin session: https://app.devin.ai/sessions/cf0e109c71cf4f2a9be8f31ede68e369
Open in Devin Desktop: https://app.devin.ai/desktop/session/cf0e109c71cf4f2a9be8f31ede68e369?variant=devin
Requested by: @pyramation