nix-rust / nix

Rust friendly bindings to *nix APIs
MIT License
2.57k stars 650 forks source link

test: Grab FORK_MTX when unmounting or forking in the mount tests #2386

Closed TheJonny closed 2 months ago

TheJonny commented 2 months ago

fork() duplicates all open file descriptors, which then could prevent a successful umount().

So either when creating file descriptors or when requiring a file descriptor to be closed, we must make sure that no child processes have copies. since wile descriptors are created all over the place, It is more practical to wait for all child processes before unlock.

TODO:

SteveLauC commented 2 months ago

Hi, thanks for working on this!

What about we set the close-on-exec flag for the test files in that bind-mount fs (as well as the fds in other mount tests), I kinda think this would be more straightforward, thoughts?

TheJonny commented 2 months ago

The close-on exec-flag will not prevent the issue, because the issue is not exec, but fork: it copies any opened file descriptors and then they live until exit or exec. if a file descriptor to something on the mountpoint is forked, unmount will fail.

SteveLauC commented 2 months ago

it copies any opened file descriptors and then they live until exit or exec.

You are right, there is still a timespan between fork() and execxxx() that could theoretically make the test fail