Skip to content
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

rootlessnetns: fix setup error when file already exists #2306

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libnetwork/internal/rootlessnetns/netns_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ func (n *Netns) getOrCreateNetns() (ns.NetNS, bool, error) {
}
// In case of errors continue and setup the network cmd again.
} else {
// Special case, the file might exist already but is not a valid netns.
// One reason could be that a previous setup was killed between creating
// the file and mounting it. Or if the file is not on tmpfs (deleted on boot)
// you might run into it as well: https://github.com/containers/podman/issues/25144
// We have to do this because NewNSAtPath fails with EEXIST otherwise
if errors.As(err, &ns.NSPathNotNSErr{}) {
// We don't care if this fails, NewNSAtPath() should return the real error.
_ = os.Remove(nsPath)
}
logrus.Debugf("Creating rootless network namespace at %q", nsPath)
// We have to create the netns dir again here because it is possible
// that cleanup() removed it.
Expand Down