- 
                Notifications
    You must be signed in to change notification settings 
- Fork 180
Improve sandbox cleanup logic #1090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
4e8bd4e    to
    71962ed      
    Compare
  
    71962ed    to
    684c443      
    Compare
  
    29bef8a    to
    c547ab3      
    Compare
  
    c547ab3    to
    0e1da21      
    Compare
  
    | @cursor review | 
| 
 This should be Ok as the noop memory never exits | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to call stop before close?
| 
 You don't need to now (because it's already handled for you), but you still can if you want to call it sooner | 
4a51822    to
    2b3eaa5      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Sandbox Shutdown Hangs Due to Missing Cancellation
In the ResumeSandbox goroutine, after sbx.Stop() is called, the subsequent Wait() calls on both Firecracker and UFFD processes lack context cancellation. This can cause the goroutine to block indefinitely if one process hasn't fully exited, potentially hanging sandbox shutdowns.
packages/orchestrator/internal/sandbox/sandbox.go#L522-L535
infra/packages/orchestrator/internal/sandbox/sandbox.go
Lines 522 to 535 in 81b2f47
| go func() { | |
| // Wait for either uffd or fc process to exit | |
| select { | |
| case <-fcUffd.Exit().Done(): | |
| case <-fcHandle.Exit.Done(): | |
| } | |
| err := sbx.Stop(context.WithoutCancel(ctx), tracer) | |
| uffdWaitErr := fcUffd.Exit().Wait() | |
| fcErr := fcHandle.Exit.Wait() | |
| exit.SetError(errors.Join(err, fcErr, uffdWaitErr)) | |
| }() | 
Improve sandbox cleanup logic to prevent accidental mistakes. The
Stopnow just stops the sandbox, whileCloseproperly cleans up the resources. You're always required to callClose, you don't need to callStop. You can also callWaitto listen for the sandbox stop event.