public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH proxmox] fix #6267: rest-server: fix task log rotation race
@ 2026-09-23 11:43 Fabian Grünbichler
  2026-09-23 16:57 ` applied: " Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Fabian Grünbichler @ 2026-09-23 11:43 UTC (permalink / raw)
  To: pbs-devel

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





^ permalink raw reply related	[flat|nested] 2+ messages in thread

* applied: [PATCH proxmox] fix #6267: rest-server: fix task log rotation race
  2026-09-23 11:43 [PATCH proxmox] fix #6267: rest-server: fix task log rotation race Fabian Grünbichler
@ 2026-09-23 16:57 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2026-09-23 16:57 UTC (permalink / raw)
  To: pbs-devel, Fabian Grünbichler

On Wed, 23 Sep 2026 13:43:12 +0200, Fabian Grünbichler wrote:
> 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
> 
> [...]

Applied, thanks!

[1/1] fix #6267: rest-server: fix task log rotation race
      commit: c999d605ddffb457640ac301b3a74fddc398aefa




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-23 16:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23 11:43 [PATCH proxmox] fix #6267: rest-server: fix task log rotation race Fabian Grünbichler
2026-09-23 16:57 ` applied: " Thomas Lamprecht

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