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

DeleteNamed() - not clearing namedPath if mount does not exist #84

Open
davidhadas opened this issue Jun 1, 2024 · 1 comment
Open

Comments

@davidhadas
Copy link

In some situations (e.g. program panic or abruptly terminated), a network namespace may be left unmounted, but with the namedPath still existing. I.e. the file system may be left with the file existing such as /run/netns/xyz but not mounted.

Further, going via a sequence of DeleteNamed() followed by NewNamed() does not resolve the situation since DeleteNamed() will not remove the file if not mounted (See code below). There seem to be no way to get the code to work in such a situation. As a minimal quick solution, I suggest modifying DeleteNamed from:

func DeleteNamed(name string) error {
	namedPath := path.Join(bindMountPath, name)

	err := syscall.Unmount(namedPath, syscall.MNT_DETACH)
	if err != nil {
		return err
	}

	return os.Remove(namedPath)
}

to be:

func DeleteNamed(name string) error {
	namedPath := path.Join(bindMountPath, name)

	err := syscall.Unmount(namedPath, syscall.MNT_DETACH)
	if err != nil {
                 os.Remove(namedPath)
		return err
	}

	return os.Remove(namedPath)
}

As a longer term, more complete solution, I would suggest adding mutex to protect this from ever happaning.

@davidhadas davidhadas changed the title DeleteNamed - not clearing namedPath if mount does not exist DeleteNamed() - not clearing namedPath if mount does not exist Jun 1, 2024
@jeffwidman
Copy link
Collaborator

A PR is most welcome. I'd vote for the longer term solution, whether that be a mutex or something else, but ideally preventing this sounds better than the brittleness of trying to do cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants