all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [PATCH proxmox] fix #6267: rest-server: fix task log rotation race
Date: Wed, 23 Sep 2026 13:43:12 +0200	[thread overview]
Message-ID: <20260923114403.856979-1-f.gruenbichler@proxmox.com> (raw)

if the task log archive files get rotated, the base `archive` file is renamed
to `archive.1`. until it is recreated, iterating over the archive files returns
no files.

on systems with a lot of task activity, task rotation could be effectively
broken:
- every logrotate task rotated the task archive files
- the subsequent handling of the archive files to find out which task logs to
  clean found no task archive files at all - only rotated copies existed

there's a small race window in rotation task:
- archives are rotated (and too old archives removed)
- old task logs are cleaned up

if the base archive file got recreated inbetween (e.g., by an unrelated task
finishing), then log rotation would clean up old task logs despite the bug.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---

Notes:
    confirmed the problematic sequence by adding a sleep at the end of the
    logrotate task in PBS, with an otherwise quiet system the archive file gets
    rotated but not recreated until the tasks exits, and not ask log cleanup
    happens.
    
    with this patch in place, old task logs get cleaned up as expected.

 proxmox-rest-server/src/worker_task.rs | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs
index 63f0c14c..a901985b 100644
--- a/proxmox-rest-server/src/worker_task.rs
+++ b/proxmox-rest-server/src/worker_task.rs
@@ -303,6 +303,21 @@ pub fn rotate_task_log_archive(
 
     let mut rotated = logrotate.rotate(size_threshold)?;
 
+    // need to recreate base file after rotation
+    if rotated {
+        let options = setup
+            .file_opts
+            .perm(nix::sys::stat::Mode::from_bits_truncate(0o660));
+
+        atomic_open_or_create_file(
+            &setup.task_archive_fn,
+            OFlag::O_APPEND | OFlag::O_RDWR,
+            &[],
+            options,
+            false,
+        )?;
+    }
+
     if let Some(max_days) = max_days {
         // NOTE: not on exact day-boundary but close enough for what's done here
         let cutoff_time = proxmox_time::epoch_i64() - (max_days * 24 * 60 * 60) as i64;
-- 
2.47.3





             reply	other threads:[~2026-09-23 11:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 11:43 Fabian Grünbichler [this message]
2026-09-23 16:57 ` applied: [PATCH proxmox] fix #6267: rest-server: fix task log rotation race Thomas Lamprecht

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=20260923114403.856979-1-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@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