mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #914] strata-vision helper leaks /tmp/strata-vision-* temp dirs (unbounded growth -> OOM on tmpfs /tmp) #396
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#396
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cubacrazy on GitHub (Oct 5, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/914
On v0.1.38 (CUDA 13.4 build, RTX 3090 Ti, CachyOS),
strata-visioncreates a freshmkdtempdirectory/tmp/strata-vision-<rand>/for every vision request, filled with.svescratch files (~150-200 MB per dir), and never removes them - neither after the request nor on helper exit.Observed after ~1 day of normal native-vision traffic: 120 leaked dirs ~ 12 GB. On distros where
/tmpis tmpfs (CachyOS, Fedora defaults), this consumes physical RAM directly and pushes the overflow into zram, which is also RAM - our 62 GiB box hit 62/62 GiB used with 420 MB available and nearly OOMed.Repro: run the vision path repeatedly (
--vision --vram-reserve-mib 700, OpenAI-styleimage_urlrequests), watchls -d /tmp/strata-vision-* | wc -lgrow monotonically; each dir contains multiple ~10 MB.svefiles.Expected: helper unlinks its temp dirs after each request (or at least on clean exit), or reuses a single scratch dir per helper process.
Workaround we run meanwhile:
0 */6 * * * find /tmp -maxdepth 1 -name 'strata-vision-*' -type d -mmin +360 -exec rm -rf {} +@talisp commented on GitHub (Oct 5, 2026):
Data point (Linux, 0.1.38 and 0.1.39, NVIDIA): here it is one directory per server start, not per request. It is created in
serve/server.py:1275(Vision.__init__,tempfile.mkdtemp(prefix="strata-vision-")). It holds one<hash>.sveper unique image (~9–10 MB each; repeated images reuse it). The cache keeps at most 64 of them (the oldest are deleted), so a single run stays bounded (~600 MB), but the directory itself is never removed when the server stops.A directory from yesterday's run is still here: 64 files (the cap), 596 MB. Today's: 16 files, 147 MB.
So setups that restart the server or the helper often (idle unload, crashes, updates) accumulate one such directory per restart. Removing
self.diron exit, or reusing one fixed per-install cache directory, would cover that. (Edited: the first version said the per-image files were never removed; they are, past 64.)@fouyzjl commented on GitHub (Oct 6, 2026):
Concrete numbers on v0.1.39 (Ubuntu, RTX 4090,
vision.max_tokens: 8192— the per-image budget raised from the 1,024 default), which make the disk side of this worse than the ~150-200 MB/request and ~600 MB/run in the report above:The 64-entry cap is a count, not bytes (
serve/server.py:1368), and one entry is one unique image. At an 8192-token image budget a full 2481x3508 page becomes a 79.4 MiB<hash>.sve, so one server process's directory reaches ~5 GB (64 x 79 MB), not ~600 MB. We measured 2.7 GB with mixed sizes, then 4.4 GB after 16 full-page images displaced them. With no removal on exit, every server start adds another such directory. (Our/tmpis ext4, so for us this is disk; on a tmpfs it would be ~5 GB of RAM per run dir.)Related: a cache hit does not refresh an entry's position (
if key in self.cache: return self.cache[key]), so an image that is requested repeatedly can still sit at the front of the FIFO and be evicted.Two paths we instrumented while chasing a truncated stream upstream of us (analysis, not an observed failure):
encode()unlinks the oldest<hash>.sveunconditionally on overflow (:1369-1370, no reference check), while another request can be between itsencode()and thef.write(path.read_bytes())that combines the images (:2180-2182);self.embeddings.pathis per-service state, set when a request's images are combined (:2183) and re-read inrun()(:2257); with two image requests in flight, B's combine can overwrite A's path, and thefinally(:2459-2460) then unlinks whatever was set last.Reproduction attempt, for the record: 16 image requests, 4 at a time, all unique images, cache held at its 64-entry cap -> 16/16 streams ended with
data: [DONE], no error. The four "concurrent" requests serialized (serving: 1), so those two windows never overlapped here. Reporting them as latent only; the practical impact we see is the disk side above.@Niko1221 commented on GitHub (Oct 6, 2026):
Fixed in 0.1.40: when the server ends (Ctrl+C or a normal stop), it removes the image encoder's scratch directory, so /tmp/strata-vision-* no longer piles up one per start. An idle unload keeps the directory (the encoded images stay cached for the restart). A directory left by a crash or kill is not swept; the
find /tmp ... -mmin +360cron is still the way to clean those.@fouyzjl commented on GitHub (Oct 6, 2026):
Correction to my previous comment, with the evidence I did not have then: the
encode()eviction path does bite in production.serve/server.py:2182inprepare():The path returned by
encode()was gone by the timeprepare()combined it: the file was unlinked by another request's cache overflow (:1369-1370). The handler thread ends there, so the response is never written - a client that was streaming sees the connection end withoutdata: [DONE]. Our fronting proxy treats that as an unconfirmed completion and pauses; that is how we noticed.What made it reachable here, since it was not in my earlier 4-at-a-time attempt: the two image requests were not queued behind each other at the engine (
serving: 1only serializes the engine's own work).prepare()- the image encoding, the combine, the tokenizer - runs before the engine is engaged, so two callers can be inside it at the same time even on a single-slot server.So the unlink is not merely latent. A cheap fix on the same line: do not unlink on eviction (drop the dict entry only), or defer the unlink to the end of the request that owns the path. Worth a look either way; thanks for the dir-leak fix in advance.
@fouyzjl commented on GitHub (Oct 6, 2026):
Follow-up with a deterministic, single-request reproduction - no concurrency needed, and it corrects my previous explanation:
encode()returns a path for each image of a request, and the request then reads those paths to combine them (:2180-2182). If the request's first image is a cache hit whose entry is the oldest inself.cache, and a later image of the same request misses, that insert evicts the oldest entry - the first image's own file - before the combine reads it:Reproduced on the first try (320x240 PNGs, one completion each):
X(insert; becomes the oldest entry once 63 more unique images are inserted);Xnow at the front);[X, Y](X= hit,Y= new):->
RemoteDisconnected: Remote end closed connection without response, 0.01 s, andXalone afterwards:200(re-encoded);[Y2, X](miss first, hit second):200- so it is the order, and the eviction of an image the same request already holds.This also explains why my earlier 4-at-a-time attempt reproduced nothing: one image per request never puts an evicted entry and a reader in the same request. A cache hit does not refresh an entry's position (
if key in self.cache: return self.cache[key]), so a repeatedly sent image (a page sent with every figure-crop/figure-review request) walks to the front of the FIFO and is the first to be evicted.The unlink on
:1370is therefore hit by ordinary single-caller traffic, not only by an unusual concurrent one. Not unlinking there (popping the dict entry only), or deferring it past the request that owns the path, would remove it.@fouyzjl commented on GitHub (Oct 6, 2026):
A three-line fix for the reproduction above, verified here (whole-page + figure-crop style multi-image requests, cache held at its 64-entry cap):
Measured here, before -> after:
[X, Y], X = oldest hit, Y = miss (the reproduction)RemoteDisconnected200<hash>.sveby hand, then send that imageRemoteDisconnected200[X, Y]RemoteDisconnected200[Y, X](miss first)200200The
exists()check on a hit is what makes the retry effective: without itencode()returns the same missing path and the second read fails the same way (I measured that too). The unlink is the actual bug; the other two are belt and braces for anything else that removes scratch files while the server runs (afind /tmp -deletestyle cleanup did it to us once).Happy to send this as a PR if that is easier than applying it by hand - just say which branch you want it against. (It is a local patch here, with the original kept aside.)