public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Kefu Chai <k.chai@proxmox.com>
To: w.bumiller@proxmox.com
Cc: pve-devel@lists.proxmox.com
Subject: Re: [PATCH common 1/2] cmd: run: do not cancel the caller's alarm
Date: Mon,  9 Nov 2026 14:58:35 +0800	[thread overview]
Message-ID: <20261109065835.1694200-1-k.chai@proxmox.com> (raw)
In-Reply-To: <cgsng52kirt4qcaehzqlb75kqttxcgjirdgum6ndwp7ym6ag2d@p254xv6gnjv4>

Hi Wolfgang,

thanks for the review!

> There is technically a race here where at *this* point the outer alarm
> can trigger.
>
> I suggest placing
>
>     $oldtimeout = alarm(0) if $timeout;
>
> *above* the `local $SIG{ALRM}` line above first, so that if a timeout is
> created, we first disable the alarm, then establish the signal handler,
> *then* the new alarm (without re-assigning to `$oldtimeout` again).

Good catch, the v2 does exactly that.

[snip]

> This now means an external timer can interrupt `$errfunc` which it could
> not previously.
>
> I think it makes more sense to `eval` the `$errfunc` call and do
> something like:
>
>     if ($err eq "got timeout\n") {
>         warn $errfunc_error;
>     } else {
>         $err = "$errfunc_error\n$err";
>     }

Done like that. The new test has an errfunc that dies on the flushed
line: run still reports its timeout and only warns the error.

[snip]

> ...then move this hunk to after the kill/wait code below, replacing
> its `die`s with appending the error similar to the above code, so
> the external timer also cannot prevent the kill/wait.
>
> This might then also make the 2nd patch unnecessary?

The series already has that order: the second patch kills and reaps
the command right after the eval, before the flush and before the
caller's alarm is re-armed. The dies on the error paths come after
the reap, so they cannot skip it either.

But I don't think the second patch becomes redundant, because that
unconditional kill/wait is what it adds in the first place. In the
first patch alone, the kills sit on the timeout, sysread and callback
paths. When the caller's alarm handler is what dies while the command
runs, the 'rbd create' case, nothing kills the command, however the
first patch is ordered.

Happy to fold the two into one patch if that reads better. I kept
them apart because they fix two different things.

One window stays open on purpose: without a timeout of its own, run
leaves the caller's alarm armed during the kill/wait too, so its
handler can still die between the eval and the kill. Disarming it
there would leave nothing to break out of the waitpid when a child is
stuck in uninterruptible sleep, and I prefer keeping the caller's
watchdog working over guaranteeing the reap.

I'll send the v2 with both changes and their tests right after this.




  reply	other threads:[~2026-11-09  6:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 11:01 [PATCH common 0/2] cmd: run: do not leave the command behind on a caller's timeout Kefu Chai
2026-10-21 11:01 ` [PATCH common 1/2] cmd: run: do not cancel the caller's alarm Kefu Chai
2026-11-05 13:20   ` Wolfgang Bumiller
2026-11-09  6:58     ` Kefu Chai [this message]
2026-10-21 11:01 ` [PATCH common 2/2] cmd: run: kill the command when run dies Kefu Chai
2026-11-09  8:04 ` [PATCH common 0/2] cmd: run: do not leave the command behind on a caller's timeout Kefu Chai

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=20261109065835.1694200-1-k.chai@proxmox.com \
    --to=k.chai@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=w.bumiller@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal