From: Gabriel Goller <g.goller@proxmox.com>
To: Christian Ebner <c.ebner@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH proxmox-backup v2] client: mount: flush output before exiting
Date: Tue, 18 Jun 2024 15:10:52 +0200 [thread overview]
Message-ID: <20240618131052.uc3tuxx6lisvea4m@luna.proxmox.com> (raw)
In-Reply-To: <52d3ae5f-ed06-42cc-a189-82326e735234@proxmox.com>
On 18.06.2024 15:00, Christian Ebner wrote:
>On 6/18/24 14:29, Gabriel Goller wrote:
>>
>>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
>>:(.
>
>That is actually true, no point in flushing here. So my suggestion for
>the fix was wrong, as I was primed on the error location :(
>
And I blindly followed :)
>>
>>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)
We actually need to also check the Ok branch if the passed buffer is
empty because if the fd get's closed we don't get an error code back.
Will submit a v3 shortly!
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2024-06-18 13:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-14 9:39 Gabriel Goller
2024-06-14 9:54 ` Christian Ebner
2024-06-18 11:20 ` Friedrich Weber
2024-06-18 11:41 ` Christian Ebner
2024-06-18 12:29 ` Gabriel Goller
2024-06-18 13:00 ` Christian Ebner
2024-06-18 13:10 ` Gabriel Goller [this message]
2024-06-18 12:32 ` Friedrich Weber
2024-06-18 12:42 ` Christian Ebner
2024-06-18 12:53 ` Gabriel Goller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240618131052.uc3tuxx6lisvea4m@luna.proxmox.com \
--to=g.goller@proxmox.com \
--cc=c.ebner@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox