From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id A75B61FF0DE for ; Thu, 19 Nov 2026 12:06:26 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 728182169B; Thu, 19 Nov 2026 12:06:26 +0100 (CET) Message-ID: <8395064a-fd0b-4db4-bb75-9b1cf96fe8b9@proxmox.com> Date: Thu, 19 Nov 2026 12:06:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH proxmox 4/4] rest-server: clamp old task log cleanup cutoff to earliest active task To: Robert Obkircher , pbs-devel@lists.proxmox.com References: <20261118180228.341628-1-c.ebner@proxmox.com> <20261118180228.341628-5-c.ebner@proxmox.com> Content-Language: en-US, de-DE From: Christian Ebner In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795086382550 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.360 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 7C7DVXFVXWNKHWUTZ2PQEFLEK6MS2YRB X-Message-ID-Hash: 7C7DVXFVXWNKHWUTZ2PQEFLEK6MS2YRB X-MailFrom: c.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 11/19/26 11:55 AM, Robert Obkircher wrote: > > On 18.11.26 19:02, Christian Ebner wrote: >> Determining the cutoff timestamp for old task log cleanup previously >> only inspected the oldest entry in the task archive, which only tracks >> finished tasks. Still running tasks are listed exclusively in the >> active tasks file without an end time. >> >> If a long-running task started before the calculated archive cutoff >> time and has not written any new log lines since then, its log file's >> mtime is older than the cutoff time and cleanup_old_tasks() would >> remove the log file while the task is still active. >> >> Prevent this by also reading the active task list while holding the >> shared task list lock during cutoff time gathering and clamping the >> cutoff timestamp to the earliest active task's start time. Since a >> task's log file is created after its UPID start time is generated, >> its mtime is guaranteed to be at or after that timestamp. >> >> Signed-off-by: Christian Ebner >> --- >> proxmox-rest-server/src/worker_task.rs | 15 ++++++++++++--- >> 1 file changed, 12 insertions(+), 3 deletions(-) >> >> diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs >> index 80889451..f1f27ec2 100644 >> --- a/proxmox-rest-server/src/worker_task.rs >> +++ b/proxmox-rest-server/src/worker_task.rs >> @@ -264,7 +264,8 @@ impl WorkerTaskSetup { >> } >> >> /// Identify the oldest finished task entry's timestamp by iterating the task >> - /// archive and return the calculated cutoff time. >> + /// archive, clamped to the earliest active task's start time, and return the >> + /// calculated cutoff time. >> /// >> /// Note: acquired a shared lock on [`WorkerTaskSetup::task_lock_fn`]. >> fn oldest_task_cutoff_time(&self, compressed: bool,) -> Result, Error> { >> @@ -277,7 +278,15 @@ impl WorkerTaskSetup { >> for line in reader.lines() { >> let line = line?; >> if let Ok((_, _, Some(state))) = parse_worker_status_line(&line) { >> - let timestamp = state.endtime(); >> + let mut timestamp = state.endtime(); >> + >> + if let Some(oldest_active) = read_task_file_from_path(&self.active_tasks_fn)? > Couldn't this be read once outside of the loops? Yeah, better to gather the latest active right after locking. Will send a v2 dropping patch 1 and pulling this out of the loop, thanks. >> + .into_iter() >> + .map(|info| info.upid.starttime) >> + .min() >> + { >> + timestamp = timestamp.min(oldest_active); >> + } >> >> let cutoff_time = if timestamp > 0 { >> SystemTime::UNIX_EPOCH.checked_add(Duration::from_secs(timestamp as u64)) >> @@ -385,7 +394,7 @@ pub fn rotate_task_log_archive( >> } >> >> /// removes all task logs that are older than the oldest task entry in the >> -/// task archive >> +/// task archive and not currently active >> pub fn cleanup_old_tasks(compressed: bool) -> Result<(), Error> { >> let setup = worker_task_setup()?; >>