fix(sql-cache): measure the 5kb stored-SQL cap in UTF-8 bytes - #355
Open
OsamaAnsar wants to merge 1 commit into
Open
fix(sql-cache): measure the 5kb stored-SQL cap in UTF-8 bytes#355OsamaAnsar wants to merge 1 commit into
OsamaAnsar wants to merge 1 commit into
Conversation
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.
Closes #353.
Problem
SqlCache.applyguards sqld's 5 KB stored-SQL cap withsqlText.length >= 5000, which counts UTF-16 code units. sqld enforces that cap in UTF-8 bytes (req.sql.len()inlibsql-server/src/hrana/http/request.rs).Any statement that falls between the two measures is cached and
store_sql'd by the client, refused by the server, and then every later batch that references itssql_idfails withSQL text <id> not found. Pure-ASCII SQL is unaffected because the two measures coincide; the bug only shows up once statements carry multibyte text (CJK, accented Latin, emoji), which makes it look like a data-dependent protocol error rather than a size limit.Fix
Measure the guard in the same units the server does:
TextEncoderis available on every runtime this package targets. The client's>= 5000stays one byte stricter than the server's> 5000; that direction is safe (the client just sends a borderline statement inline instead of caching it), so this PR leaves it as-is.Test
New
packages/libsql-client/src/__tests__/sql_cache.test.tswith a fakeSqlOwner:The middle case fails on
mainwithout the fix and passes with it.Verification
sql_cache,uri,configunit suites pass;tsc --noEmitandprettier --checkcleanclient.test.tslocally (it needs the Pythonhrana-test-server, and I'm on Windows without a working Python) — relying on CI for the integration matrix. Happy to add more coverage if you'd like.Scope
Kept to the units fix. The issue mentions two optional follow-ups — surfacing the refused
store_sqlerror to the caller instead of only into_setClosed, and documenting the cap's units in the guard comment — which I'd be glad to do in separate PRs.