[pbs-devel] [PATCH proxmox-backup v2] client: mount: flush output before exiting

Gabriel Goller g.goller at proxmox.com
Tue Jun 18 14:29:16 CEST 2024


On 18.06.2024 13:41, Christian Ebner wrote:
>On 6/18/24 13:20, Friedrich Weber wrote:
>>Thanks for tackling this! I ran into this issue (sometimes missing error
>>output) when I was running `sudo proxmox-backup-client mount [...]` and
>>forgot that PBS_REPOSITORY was not passed through by sudo. It looks like
>>in this case, the patch doesn't completely fix this issue -- seems like
>>I'm still missing the error output sometimes:
>>
>>$ sudo ./proxmox-backup-client mount \
>>         "$SNAPSHOT" $FILE $PATH \
>>         --keyfile $KEYFILE --ns $NS
>>$ sudo ./proxmox-backup-client mount \
>>         "$SNAPSHOT" $FILE $PATH \
>>         --keyfile $KEYFILE --ns $NS
>>$ sudo ./proxmox-backup-client mount \
>>         "$SNAPSHOT" $FILE $PATH \
>>         --keyfile $KEYFILE --ns $NS
>>Error: unable to get (default) repository
>
>Hi Friedrich,
>I just double checked by invoking the command in a for loop 10 times, 
>for all of which I do get the error message as output.
>
>```bash
>for i in $(seq 0 9)
>do
>	sudo proxmox-backup-client mount ct/100/2024-06-13T10:38:54Z root.pxar /mnt
>done
>```
>
>Interestingly, I do also get the output without the patch applied, so 
>therefore I did not notice (and obviously forgot to do the negative 
>test during review).
>
>Maybe some difference in setup?
>
>Cheers,
>Chris

Hmm I think I know what happens...
This patch is flaky for me as well, sometimes it works, sometimes it
doesn't. The problem is that we move the `pw` file descriptor to
`mount_do`, which means that after it returns, the file_descriptor gets
dropped.

     let (pr, pw) = proxmox_sys::pipe()?;
     let pr: OwnedFd = pr.into(); // until next sys bump
     let pw: OwnedFd = pw.into();
     match unsafe { fork() } {
         Ok(ForkResult::Parent { .. }) => {
             drop(pw);
             // Blocks the parent process until we are ready to go in the child
             let _res = nix::unistd::read(pr.as_raw_fd(), &mut [0]).unwrap();
             Ok(Value::Null)
         }
         Ok(ForkResult::Child) => {
             drop(pr);
             nix::unistd::setsid().unwrap();
             let result = proxmox_async::runtime::main(mount_do(param, Some(pw)));
                                                                            ^^^
pw gets dropped here, which means the fd is closed.

             io::stdout().flush()?;
             io::stderr().flush()?;
             result
         }
         Err(_) => bail!("failed to daemonize process"),
     }


In the parent process we read from the fd—which is then closed—meaning
that the parent exits at the same time as we do the stderr/stdout flush.

And actually this patch was stupid to begin with, because we don't even
print the error in the mound_do function, but later in the api-handler
:(.

I think we need to do something like this:

     if let Err(e) = nix::unistd::read(pr.as_raw_fd(), &mut [0]) {
         // if the fd is closed, or some other error happens, wait so
         // that the child can return the error safely, then exit 
         nix::sys::wait::wait().unwrap();
     }
     Ok(Value::Null)






More information about the pbs-devel mailing list