Skip to content

Commit

Permalink
libpod: configureNetNS() tear down on errors
Browse files Browse the repository at this point in the history
Make sure to tear down the netns again on errors. This is needed when a
later call fails and we do not have already stored the netns in the
container state.

[NO NEW TESTS NEEDED] My ginkgo-v2 PR will catch problem like this once
merged.

Fixes containers#18205

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed May 23, 2023
1 parent d812087 commit 97ec57d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libpod/networking_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,14 @@ func (r *Runtime) configureNetNS(ctr *Container, ctrNS string) (status map[strin
if err != nil {
return nil, err
}
defer func() {
// do not forget to tear down the netns when a later error happened.
if rerr != nil {
if err := r.teardownNetworkBackend(ctrNS, netOpts); err != nil {
logrus.Warnf("failed to teardown network after failed setup: %v", err)
}
}
}()

// set up rootless port forwarder when rootless with ports and the network status is empty,
// if this is called from network reload the network status will not be empty and we should
Expand Down

0 comments on commit 97ec57d

Please sign in to comment.