Close gofer filestore FDs in failure cases.

This is consistent with how other FDs are closed. This is so we don't leak FDs
if they are not consumed.

PiperOrigin-RevId: 578638281
This commit is contained in:
Ayush Ranjan
2023-11-01 14:17:32 -07:00
committed by gVisor bot
parent 429f7c4396
commit 8f9211abca
3 changed files with 14 additions and 3 deletions
+5
View File
@@ -346,6 +346,11 @@ func (cm *containerManager) StartSubcontainer(args *StartArgs, _ *struct{}) erro
goferFilestoreFDs = append(goferFilestoreFDs, goferFilestoreFD)
}
goferFiles = goferFiles[args.NumGoferFilestoreFDs:]
defer func() {
for _, fd := range goferFilestoreFDs {
_ = fd.Close()
}
}()
goferFDs, err := fd.NewFromFiles(goferFiles)
if err != nil {
+6 -3
View File
@@ -598,9 +598,9 @@ func (l *Loader) Destroy() {
// Release any dangling tcp connections.
tcpip.ReleaseDanglingEndpoints()
// In the success case, stdioFDs and goferFDs will only contain
// released/closed FDs that ownership has been passed over to host FDs and
// gofer sessions. Close them here in case of failure.
// In the success case, all FDs in l.root will only contain released/closed
// FDs whose ownership has been passed over to host FDs and gofer sessions.
// Close them here in case of failure.
for _, f := range l.root.stdioFDs {
_ = f.Close()
}
@@ -610,6 +610,9 @@ func (l *Loader) Destroy() {
for _, f := range l.root.goferFDs {
_ = f.Close()
}
for _, f := range l.root.goferFilestoreFDs {
_ = f.Close()
}
l.stopProfiling()
}
+3
View File
@@ -467,6 +467,9 @@ func (c *Container) Start(conf *config.Config) error {
for _, f := range goferFiles {
_ = f.Close()
}
for _, f := range goferFilestores {
_ = f.Close()
}
}()
cleanMounts, err := specutils.ReadMounts(mountsFile)