From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 33FED1FF13C for ; Thu, 02 Apr 2026 18:36:00 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C67151F673; Thu, 2 Apr 2026 18:36:29 +0200 (CEST) Message-ID: <0a97d1d7-6e1e-49b7-a34d-5a19aba2c105@proxmox.com> Date: Thu, 2 Apr 2026 18:35:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH proxmox-backup v3 2/3] fix #7400: api: gracefully handle corrupted job statefiles To: =?UTF-8?Q?Michael_K=C3=B6ppl?= , pbs-devel@lists.proxmox.com References: <20260325160617.342295-1-m.koeppl@proxmox.com> <20260325160617.342295-3-m.koeppl@proxmox.com> Content-Language: en-US, de-DE From: Christian Ebner In-Reply-To: <20260325160617.342295-3-m.koeppl@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1775147697553 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.431 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 1 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 1 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 1 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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: WRPTQFIW723JKCSF5OGCG3D7QFRBLVKW X-Message-ID-Hash: WRPTQFIW723JKCSF5OGCG3D7QFRBLVKW 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: One nit inline. Other than that: Reviewed-by: Christian Ebner On 3/25/26 5:06 PM, Michael Köppl wrote: > Introduce Unknown JobState to more explicitly represent cases where the > state could not be determined, e.g. if the statefile was corrupted or > missing. Update JobState::load to handle parsing errors (both for > statefiles themselves as well as UPIDs) and return an Unknown state if > such an error occurred. Update compute_schedule_status to also handle > the new Unknown status, returning a default JobScheduleStatus so API > endpoints don't return an error to the user, stopping them from viewing > their jobs. > > Signed-off-by: Michael Köppl > --- > src/server/jobstate.rs | 48 ++++++++++++++++++++++++++++++++++++------ > 1 file changed, 42 insertions(+), 6 deletions(-) > > diff --git a/src/server/jobstate.rs b/src/server/jobstate.rs > index ceac8dde8..4163656e8 100644 > --- a/src/server/jobstate.rs > +++ b/src/server/jobstate.rs > @@ -66,6 +66,7 @@ pub enum JobState { > state: TaskState, > updated: Option, > }, > + Unknown, > } > > /// Represents a Job and holds the correct lock > @@ -155,6 +156,7 @@ pub fn update_job_last_run_time(jobtype: &str, jobname: &str) -> Result<(), Erro > state, > updated: Some(time), > }, > + JobState::Unknown => bail!("cannot update last run time for unknown job state"), > }; > job.write_state() > } > @@ -179,6 +181,7 @@ pub fn last_run_time(jobtype: &str, jobname: &str) -> Result { > .map_err(|err| format_err!("could not parse upid from state: {err}"))?; > Ok(upid.starttime) > } > + JobState::Unknown => bail!("statefile could not be parsed or was empty"), > } > } > > @@ -191,11 +194,20 @@ impl JobState { > /// This does not update the state in the file. > pub fn load(jobtype: &str, jobname: &str) -> Result { > if let Some(state) = file_read_optional_string(get_path(jobtype, jobname))? { > - match serde_json::from_str(&state)? { > + let job_state = serde_json::from_str(&state).unwrap_or_else(|err| { > + log::error!("could not parse statefile for {jobname}: {err}"); > + JobState::Unknown nit: This should early return IMHO, no need to fall trough to the match statement below. > + }); > + > + match job_state { > JobState::Started { upid } => { > - let parsed: UPID = upid > - .parse() > - .map_err(|err| format_err!("error parsing upid: {err}"))?; > + let parsed: UPID = match upid.parse() { > + Ok(parsed) => parsed, > + Err(err) => { > + log::error!("error parsing upid for {jobname}: {err}"); > + return Ok(JobState::Unknown); > + } > + }; > > if !worker_is_active_local(&parsed) { > let state = upid_read_status(&parsed).unwrap_or(TaskState::Unknown { > @@ -211,6 +223,21 @@ impl JobState { > Ok(JobState::Started { upid }) > } > } > + JobState::Finished { > + upid, > + state, > + updated, > + } => { > + if let Err(err) = upid.parse::() { > + log::error!("error parsing upid for {jobname}: {err}"); > + return Ok(JobState::Unknown); > + } > + Ok(JobState::Finished { > + upid, > + state, > + updated, > + }) > + } > other => Ok(other), > } > } else { > @@ -263,6 +290,7 @@ impl Job { > JobState::Created { .. } => bail!("cannot finish when not started"), > JobState::Started { upid } => upid, > JobState::Finished { upid, .. } => upid, > + JobState::Unknown => bail!("cannot finish job with unknown status"), > } > .to_string(); > > @@ -305,8 +333,15 @@ pub fn compute_schedule_status( > jobname: &str, > schedule: Option<&str>, > ) -> Result { > - let job_state = JobState::load(jobtype, jobname) > - .map_err(|err| format_err!("could not open statefile for {jobname}: {err}"))?; > + let job_state = match JobState::load(jobtype, jobname) { > + Ok(job_state) => job_state, > + Err(err) => { > + log::error!( > + "could not open statefile for {jobname}: {err} - falling back to default job schedule status", > + ); > + return Ok(JobScheduleStatus::default()); > + } > + }; > > let (upid, endtime, state, last) = match job_state { > JobState::Created { time } => (None, None, None, time), > @@ -327,6 +362,7 @@ pub fn compute_schedule_status( > last, > ) > } > + JobState::Unknown => (None, None, None, proxmox_time::epoch_i64() - 30), > }; > > let mut status = JobScheduleStatus {