[pbs-devel] applied: [PATCH/RFC proxmox-backup] rest server: daemon: update PID file before sending MAINPID notification

Thomas Lamprecht t.lamprecht at proxmox.com
Thu May 12 12:04:04 CEST 2022


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 at 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!





More information about the pbs-devel mailing list