mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
runsc: Don't close the control server in a defer.
Closing the control server will block until all open requests have completed. If a control server method panics, we end up stuck because the defer'd Destroy function will never return. PiperOrigin-RevId: 204354676 Change-Id: I6bb1d84b31242d7c3f20d5334b1c966bd6a61dbf
This commit is contained in:
committed by
Shentubot
parent
41e0b977e5
commit
67507bd579
@@ -347,9 +347,12 @@ func newProcess(spec *specs.Spec, conf *Config, ioFDs []int, console bool, creds
|
||||
}
|
||||
|
||||
// Destroy cleans up all resources used by the loader.
|
||||
//
|
||||
// Note that this will block until all open control server connections have
|
||||
// been closed. For that reason, this should NOT be called in a defer, because
|
||||
// a panic in a control server rpc would then hang forever.
|
||||
func (l *Loader) Destroy() {
|
||||
if l.ctrl != nil {
|
||||
// Shut down control server.
|
||||
l.ctrl.srv.Stop()
|
||||
}
|
||||
l.stopSignalForwarding()
|
||||
|
||||
+2
-3
@@ -142,24 +142,23 @@ func (b *Boot) Execute(_ context.Context, f *flag.FlagSet, args ...interface{})
|
||||
}
|
||||
|
||||
// Create the loader.
|
||||
|
||||
l, err := boot.New(spec, conf, b.controllerFD, b.restoreFD, b.ioFDs.GetArray(), b.console)
|
||||
|
||||
if err != nil {
|
||||
Fatalf("error creating loader: %v", err)
|
||||
}
|
||||
defer l.Destroy()
|
||||
|
||||
// Wait for the start signal from runsc.
|
||||
l.WaitForStartSignal()
|
||||
|
||||
// Run the application and wait for it to finish.
|
||||
if err := l.Run(); err != nil {
|
||||
l.Destroy()
|
||||
Fatalf("error running sandbox: %v", err)
|
||||
}
|
||||
|
||||
ws := l.WaitExit()
|
||||
log.Infof("application exiting with %+v", ws)
|
||||
*waitStatus = syscall.WaitStatus(ws.Status())
|
||||
l.Destroy()
|
||||
return subcommands.ExitSuccess
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user