Skip to content

implement UFFD failure handling and unit tests#2856

Open
AdaAibaby wants to merge 2 commits into
e2b-dev:mainfrom
AdaAibaby:feat/uffd-failure-handling-unit-test
Open

implement UFFD failure handling and unit tests#2856
AdaAibaby wants to merge 2 commits into
e2b-dev:mainfrom
AdaAibaby:feat/uffd-failure-handling-unit-test

Conversation

@AdaAibaby
Copy link
Copy Markdown
Contributor

@AdaAibaby AdaAibaby commented May 29, 2026

Fixes part of #2813 : This ensures Firecracker instances are terminated correctly on UFFD faults, preventing new network and iptables leaks. Note that the broader cleanup mechanism for existing orphans remains tracked in #2813.

Implement complete UFFD failure handling mechanism and corresponding unit tests:

  • Add failure callback mechanism in uffd.go to capture UFFD errors
  • Integrate failure callback in sandbox.go to stop sandbox gracefully on UFFD failures
  • Introduce mock memfile device for reliable unit testing
  • Add 4 fast-pass core unit tests covering main failure logic
  • Add 1 optional long-running test (skipped in short test mode)

Key design notes:

  • UFFD socket timeout is fixed at 10s by architecture and cannot be modified
  • Core logic is fully verified by fast tests to avoid long waiting
  • Long-running test is optional to balance coverage and CI efficiency

All fast tests pass, error handling is complete, and changes are minimal and compliant.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

The failure callback in uffd.go is set and read across different goroutines without synchronization, creating a data race. Additionally, because the callback is registered after the handler starts, any immediate startup failure will be missed. Protecting the callback registration and invocation with a mutex, and persisting the failure state, is required to ensure thread safety and guarantee that late-registered callbacks still receive the failure event.

Comment thread packages/orchestrator/pkg/sandbox/uffd/uffd.go
Comment thread packages/orchestrator/pkg/sandbox/uffd/uffd.go
Comment thread packages/orchestrator/pkg/sandbox/uffd/uffd.go Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 271ff3e68b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/orchestrator/pkg/sandbox/uffd/uffd.go
Address data race and late-registration issues identified in code review:

- Add sync.Mutex to guard onFailure field across goroutines
- Persist failure state (failedErr/failedSbx/failedCtx) so callbacks
  registered after a failure still receive the event immediately
- Invoke callback in a goroutine to avoid holding the lock during
  potentially slow sandbox teardown
- Add TestLateCallbackRegistrationAfterFailure to verify the guarantee
- Add TestCallbackNotInvokedOnCleanStop to verify no false positives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants