all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox Backup Server development discussion
	<pbs-devel@lists.proxmox.com>, Fabian Ebner <f.ebner@proxmox.com>
Subject: [pbs-devel] applied: [PATCH/RFC proxmox-backup] rest server: daemon: update PID file before sending MAINPID notification
Date: Thu, 12 May 2022 12:04:04 +0200	[thread overview]
Message-ID: <6a79b760-7f99-2dac-fbd6-365f4cc799c3@proxmox.com> (raw)
In-Reply-To: <20220504113324.70300-1-f.ebner@proxmox.com>

Am 5/4/22 um 13:33 schrieb Fabian Ebner:
> There is a race upon reload, where it can happen that:
> 1. systemd forks off /bin/kill -HUP $MAINPID
> 2. Current instance forks off new one and notifies systemd with the
>    new MAINPID.
> 3. systemd sets new MAINPID.
> 4. systemd receives SIGCHLD for the kill process (which is the current
>    control process for the service) and reads the PID of the old
>    instance from the PID file, resetting MAINPID to the PID of the old
>    instance.
> 5. Old instance exits.
> 6. systemd receives SIGCHLD for the old instance, reads the PID of the
>    old instance from the PID file once more. systemd sees that the
>    MAINPID matches the child PID and considers the service exited.
> 7. systemd receivese notification from the new PID and is confused.
>    The service won't get active, because the notification wasn't
>    handled.
> 
> To fix it, update the PID file before sending the MAINPID
> notification, similar to what a comment in systemd's
> src/core/service.c suggests:
>> /* Forking services may occasionally move to a new PID.
>>  * As long as they update the PID file before exiting the old
>>  * PID, they're fine. */
> but for our Type=notify "before sending the notification" rather than
> "before exiting", because otherwise, the mix-up in 4. could still
> happen (although it might not actually be problematic without the
> mix-up in 6., it still seems better to avoid).
> 
> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
> ---
> 
> An alternative would be to not tell systemd about the PIDFile at all,
> but there's two small downsides:
> * The PID file isn't cleaned up automatically when the service exits.
> * Having the PID file updated before sending the MAINPID notification
>   feels a bit cleaner (even if the PID file is not used by systemd).
> 
>  .../examples/minimal-rest-server.rs           | 18 +++++++----
>  proxmox-rest-server/src/daemon.rs             | 16 ++++++++--
>  src/bin/proxmox-backup-api.rs                 | 30 +++++++++--------
>  src/bin/proxmox-backup-proxy.rs               | 32 +++++++++++--------
>  4 files changed, 60 insertions(+), 36 deletions(-)
> 
>

applied, thanks!




      reply	other threads:[~2022-05-12 10:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-04 11:33 [pbs-devel] " Fabian Ebner
2022-05-12 10:04 ` Thomas Lamprecht [this message]

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=6a79b760-7f99-2dac-fbd6-365f4cc799c3@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=f.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal