oot asset sweep exhausts a 256 MB VM when the bucket is empty

Open
#238 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
22/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
node.js, sqlite, typescript

Research direction

Start with run-cloud-boot.js, which spawns the sweep as a second Node process, and with put_file, where the upload body comes from openAsBlob. Reproduce on a 256 MB setup with an empty bucket and a few hundred MB of assets, then record per-process memory with ps -o pid,rss,args during the sweep. Done means the process that grows is identified, with a fix or a documented minimum VM size backed by those measurements.

Written by the indexing model from the issue text.

Description

What happens

When the backup bucket is missing many assets, the boot-time sweep can exhaust a 256 MB Fly VM. The machine keeps running but stops answering: every request times out until the sweep finishes or the VM gets more memory.

Seen on sonjastojanovic after moving the app to another Fly org and switching to a new, empty Tigris bucket (see #233). The sweep had to upload 657 asset files, 314 MB in total, including videos up to 73 MB.

  • Machine: shared-cpu-1x, 256 MB (209 MB visible to the VM), no swap.
  • About 3 minutes after boot: 9 MB available, load average 3.8, no HTTP response within 30 seconds, and fly ssh sessions hanging.
  • Several uploads failed with fetch failed.
  • The site was unreachable for about 11 minutes, until the VM was scaled to 512 MB. There, the remaining 284 files uploaded in 19 seconds while the site stayed responsive. Back on 256 MB with the bucket in sync, the site is fine.

What we know

#209 had a similar out-of-memory kill, and 8069ade fixed the cause found then: put_file read each file fully into memory. That fix is deployed here, and the upload path now looks streamed. put_file passes an openAsBlob body, and aws4fetch with service: 's3' sets X-Amz-Content-Sha256: UNSIGNED-PAYLOAD, so it never hashes or buffers the body itself. Buffering whole files in our own code doesn't explain this one.

During the sweep the VM runs three processes at once:

  • the server
  • the sweep, a second Node process that run-cloud-boot.js spawns
  • the Litestream sidecar, which in this case was also failing on every sync because of #233

Nobody measured memory per process before scaling up, so we don't know which one grew.

Next steps

  • Reproduce with an empty bucket (or a new BUCKET_NAME), a few hundred MB of assets including large videos, and a 256 MB VM. Watch memory per process during the sweep with ps -o pid,rss,args.
  • Check whether Node's fetch really streams a file-backed Blob from openAsBlob, or holds large parts of it during the upload.
  • Check whether Litestream's memory grows while it retries the missing-LTX error from #233.
  • Depending on what that shows: run the sweep inside the server process instead of a second Node process, cap the sweep's heap, defer large files, or document 512 MB as the minimum for sites with large videos and automated backups.
Dominant language
TypeScript
Stars
1.8k
Forks
148
Avg merge
2h 47m
Merged PRs (30d)
13

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from michael/editable

All issues in michael/editable

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.