Skip to content

refactor(storage): consolidate read-path io wrappers - #12

Closed
levb wants to merge 14 commits into
mainfrom
lev-storage-rationalize
Closed

levb wants to merge 14 commits into
mainfrom
lev-storage-rationalize

Conversation

@levb

@levb levb commented May 19, 2026

Copy link
Copy Markdown
Owner

Fold the timer/span/gauge/cancel reader wrappers into one instrumentedReader with with* options, and gather the offset/section adapters into io_wrappers.go. Each OpenRangeReader result is now wrapped exactly once.

var rc io.ReadCloser
var cacheHit bool
var err error
switch {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if compressed, like before?

recordError(span, err)
span.End()

return nil, err
}

// The gauge counts readers serving NFS-cached data; misses fetch remotely.
opts := []readerOption{withSpan(span)}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0/5 just have the openCompressed/Uncompressed functions do the wrapping, as appropriate in their respective context?

tvi and others added 13 commits May 24, 2026 17:59
The OIDC verifier in packages/auth/pkg/auth/oidc previously enforced an
https-only scheme on both the configured issuer URL and the
discovery/JWKS URLs returned by it. This made it impossible to use a
self-hosted Hydra running on http://localhost:4444/ as an OIDC issuer
without standing up a TLS terminator in front of it.

Relax validateURL to accept http when the URL host is a loopback
address: the literal name 'localhost', any IPv4 in 127.0.0.0/8, or the
IPv6 loopback ::1. The check matches strings + parsed literal IPs only;
we deliberately do not resolve DNS so the result stays pure and
TOCTOU-free. Mirrors the same carve-out Kubernetes' apiserver applies to
--oidc-issuer-url for in-cluster test deployments.

Any non-loopback host still requires https, preserving the production
posture. Adds positive tests covering localhost, 127.0.0.1, and the IPv6
loopback; the existing non-https/non-loopback rejection test is
unchanged.
Install UFFD MISSING faults by writing source bytes into the FC-shared
memfd and calling UFFDIO_WAKE, instead of UFFDIO_COPY. Read faults arm
WP before populate so the kernel retry installs a write-protected PTE.

Behind `use-memfd-wake` (sub-flag of `use-memfd`). `resume-build
-resume-bench` compares `default` / `memfd-copy` / `memfd-wake` on the
same template.

Stacked on e2b-dev#2590.

---------

Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
Co-authored-by: Babis Chalios <babis.chalios@e2b.dev>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nikita Kalyazin <nikita.kalyazin@e2b.dev>
…2816)

The n == 0 safety net guard in pwritevAll breaks out of the retry loop
if pwritev(2) returns zero bytes written with no error, which would
otherwise spin forever. The old message called this "EOF", but pwritev()
on a regular file has no write-side EOF concept.

Rename to "no progress" which describes what actually happened: the
syscall succeeded but transferred nothing.
…v#2803)

Compression-audit correctness fixes:

- reject misaligned writes in `Cache.WriteAtWithoutLock`
- cap V4 header LZ4 decompression at the size prefix
- drop corrupt compressed cache entries on size mismatch
- retry GCS 404 within a post-transition window with backoff
- per-Read idle timeout on GCS range reads
Memfd dedup ran the page write phase synchronously on the Pause RPC,
ignoring the bgCopy detachment. Split `dedupPages` into a sync compare
and an async drain wrapped in `DedupedMemfdCache` (mirrors
`MemfdCache`); reads block via `SetOnce[*Cache].WaitWithContext`, the
goroutine owns and closes the memfd. The diff metadata/header still
comes back synchronously so `AddSnapshot`/`NewUpload` keep working
unchanged. Also coalesces contiguous dirty pages in `drainDirtyPages`
(mirrors `Cache.copyProcessMemory`) and moves the best-effort
`IsCached`/`uuid.Nil` check to per-page granularity so a single uncached
neighbour no longer poisons cached pages of the same block. Integration
matrix wires `TESTS_USE_MEMFD` so two of the three variants exercise the
new async path end-to-end.
Removes the `memory` and `populate_redis` Storage implementations along
with the in-memory `ReservationStorage`, the `SANDBOX_STORAGE_BACKEND`
config knob, and all related Terraform/HCL/CI plumbing.

- Drop `Name()` from the Storage interface and the related
`StorageName*` constants.
- Simplify `Store.Add` and `Store.Reconcile` (orphan-kill only).
- Port store/orchestrator unit tests to spin up a redis testcontainer
via `shared/pkg/redis.SetupInstance`.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Petr Vaněk <petr.vanek@e2b.dev>
e2b-dev#2814 detached only the dedup drain; the page-by-page compare and the
diff header build still ran synchronously on the Pause RPC, so deduped
pauses still scaled with dirty-page count and base-layer fetch latency.

Wrap `Snapshot.{Memfile,Rootfs}DiffHeader` in a
`*utils.SetOnce[*header.Header]`. The memfd-dedup goroutine now resolves
the header after compare; all other paths resolve it sync before
returning. `storageTemplate.Fetch` and the upload paths Wait on the
future, so the Pause RPC returns before compare/drain finishes.
…#2820)

Add .env.local template and build-debug Makefile target to match the
conventions used in packages/api for local development.
…v#2822)

`NormalizeMappings` returns its working slice (`cap == len(input)`), and
the merged `Header` is held in the orchestrator template cache for up to
25h. On snapshot-heavy nodes that unused trailing capacity is what's
dominating retained heap. Clone before returning so only the exact-size
copy survives.
@levb
levb force-pushed the lev-storage-rationalize branch from 354b7fa to aa41f01 Compare May 26, 2026 17:45
Unify the storage read path on one RangeReader interface (io.Reader +
Close(ctx)) so no wrapper stores a context. Cross-cutting read concerns
— OTEL timer/span/gauge, cancellation, and decompression — collapse into
a single `reader` configured by with* builder methods; backend leaves
are adapted via NewRangeReader.
@levb
levb force-pushed the lev-storage-rationalize branch from aa41f01 to 92433bf Compare May 26, 2026 18:23
@levb levb closed this May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants