Repository navigation
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Code Review
This pull request adds logging when the userfaultfd (uffd) handle function fails, indicating that the sandbox will be terminated, and introduces a comprehensive suite of unit tests for the uffd package. There are no review comments, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
The UFFD handle goroutine had a TODO comment stating that the sandbox should be killed when handle() fails. In fact, this is already implemented: u.exit.SetError() triggers the sandbox exit watcher in sandbox.go (line ~1093) which calls sbx.Stop(). - Remove the stale TODO comment - Add error logging when handle() fails for better observability - Add unit tests covering handle failure behavior (exit error propagation, readyCh closure, handler error state, initial state, socket creation)
The sandbox.go goroutine that monitors fcUffd.Exit().Done() was not documented as the mechanism that terminates the VM when UFFD handle() fails. Add a comment making this explicit so readers do not mistake the gap described in the now-removed uffd.go TODO for a real missing piece.
7b54ed7 to
fc647fe
Compare
5aad415 to
d71980e
Compare
|
Thank you @AdaAibaby for tracing this through to the sandbox lifecycle watcher and showing that the sandbox is already stopped when the UFFD handler fails, so the TODO is misleading, and for adding the failure log and unit tests. This branch now conflicts with main after many changes to the sandbox and uffd code, and it has had no activity for over two months, so I'm closing it for now. If you'd like to pick it up again, a fresh PR against current main with the log line and the TODO removal would be welcome, and you're free to reopen this one too. |
The uffd serve goroutine carried a stale TODO ("if the handle function fails,
we should kill the sandbox") and logged nothing when handle() failed, so a
userfaultfd failure was invisible in production.
- Remove the misleading TODO.
- Log the failure at ERROR, but only for a genuine serve-loop failure: the
existing stopping-time close (net.ErrClosed / context.Canceled) already
zeroes exitErr, so the log is gated on exitErr != nil and does not fire on
normal sandbox stop.
- Add an accurate comment on the resume-path lifecycle watcher noting that a
completed fcUffd.Exit() (which a serve-loop failure triggers) is turned into
a sandbox stop there, so a dead UFFD handler does not leave a VM without a
page-fault handler. Scoped to the resume path, which is the one that watches
fcUffd.Exit().Done().
Rebased, trimmed replacement for e2b-dev#3132 (envd/sandbox code was reworked since).
Adds a focused test asserting a handle failure surfaces a non-nil uffd exit
error - the condition that gates the new log. Revisits e2b-dev#3131.
fix #3131
What was wrong
The UFFD handle goroutine had a stale TODO comment:
The sandbox is already killed when
handle()fails — the comment was wrong and created a correctness trap. Whenu.exit.SetError()is called after ahandle()failure, it closes theExit().Done()channel. The lifecycle goroutine insandbox.go(lines 1164–1174) is watching that channel and callssbx.Stop()immediately:There was also no log line when
handle()failed, making UFFD failures invisible in production.Changes
uffd.go: Remove the stale TODO. Add an error-level log line whenhandle()fails so failures are observable.sandbox.go: Add a comment on the lifecycle goroutine'sselectblock explaining that UFFD failure flows throughExit().Done()→sbx.Stop(), making the existing mechanism explicit.uffd_test.go: Add unit tests covering handle failure behaviour: exit error propagation,readyChclosure,handlererror state, initial state, and socket creation onStart()./cc @jakubno @dobrac @ValentaTomas — Would appreciate your review on this change, thanks!