documents/import silently drops a multibyte UTF-8 character from a stored string in large request bodies
Description
A documents/import request sometimes stores a string field with one 2-byte UTF-8 character missing. The import response reports "success": true for every document. Examples from our runs:
| sent | stored |
|---|---|
клима тв чамец |
клим тв чамец |
ПРОДАВА со спална ... |
ПРОДАВ со спална ... |
од сервис се за бара |
од сервис се за бра |
НОВ соба центар продава за |
ОВ соба центар продава за |
The damage is stored. GET /collections/<c>/documents/<id> and a second export both return the shortened string.
Repro
Everything is in this gist: https://gist.github.com/joaoazevedo/9839a54ba2fee291fd0ffeedbb1be5a1
body.jsonl: 4,998 synthetic documents, 4.6 MB. Onlytitlehas non-ASCII text (Macedonian Cyrillic, in 1,203 documents).schema.json: the collection.repro.py: standard-library Python. Each run recreates the collection, imports the file (in one request by default, or--batch Ndocuments per request), checks every line of the import response, exports, and compares every field of every stored document with the source. For each difference it prints the id, field, byte offset of the lost character in the file and in the request, and theGETresult.
docker run --rm -p 8108:8108 typesense/typesense:30.2 --data-dir /tmp --api-key xyz
python3 repro.py --runs 400Observed
Fresh container per version, one client, requests sent to the published port. Each "run" is one full import of the file followed by a full comparison.
| version | documents per request | request size | runs with a damaged document |
|---|---|---|---|
| 30.2 | 4,998 (whole file) | 4.6 MB | 32 / 400 |
| 30.2 | 2,000 | up to 1.87 MB | 21 / 300 |
| 30.2 | 1,000 | up to 0.94 MB | 14 / 300 |
| 30.2 | 500 | up to 0.47 MB | 2 / 300 |
| 30.2 | 200 | up to 0.19 MB | 0 / 300 |
| 29.0 | 4,998 (whole file) | 4.6 MB | 14 / 200 |
All 90 differences (76 on 30.2, 14 on 29.0) are the sent value with exactly one 2-byte character removed. No ASCII character was lost, in title or in any other field. A damaged run had one to three damaged documents. The earliest lost character sat 213,642 bytes into its request. Some positions recur across runs: the same character of corpus-listing-001420 was lost in 6 of the 32 whole-file runs.
We saw the same thing earlier on a longer-lived 30.2 and 29.0 setup, at a lower rate (10 of 570 whole-file imports), both from a sibling container and over loopback inside the Typesense container's own network namespace.
Hypothesis
This is a guess and we haven't read the code. The loss grows with request size and only ever hits a multibyte character, which fits a character split across two body chunks and then dropped whole when the chunks are joined or parsed.
Workaround
Smaller import requests. 200 documents per request (about 190 KB) produced no damage in 300 runs, but we can't say what size is safe.
Environment
- Typesense 30.2 and 29.0, official Docker images (
typesense/typesense:30.2,typesense/typesense:29.0), single node, default settings apart from--data-dirand--api-key - Host: macOS 26.6 on Apple silicon, OrbStack, containers running aarch64
- Client: Python
urllib,Content-Type: text/plain,action=create
Source: typesense/typesense