Skip to content

Commit

Permalink
Close gofer filestore FDs in failure cases.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ayushr2 authored and gvisor-bot committed Nov 1, 2023
1 parent 429f7c4 commit 8f9211a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions runsc/boot/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions runsc/boot/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand Down
3 changes: 3 additions & 0 deletions runsc/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8f9211a

Please sign in to comment.