public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox Backup Server development discussion
	<pbs-devel@lists.proxmox.com>,
	Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup] rest-server: cleanup_old_tasks: improve error handling
Date: Mon, 28 Mar 2022 08:30:04 +0200	[thread overview]
Message-ID: <013ab17d-2ebf-aaca-0ce5-9eeabccba9c4@proxmox.com> (raw)
In-Reply-To: <20220325123816.3865356-1-d.csapak@proxmox.com>

On 25.03.22 13:38, Dominik Csapak wrote:
> by not bubbling up most errors, and continuing on. this avoids that we
> stop cleaning up because e.g. one directory was missing.

continuing is OK but if an those errors are encountered I'd still return an Err(),
and not an Ok(), at the end to make any caller easily distinguish the full OK or
error case.

If we expect such errors to happen there's something wrong with the general approach,
then the known false positives should be filtered.

> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>  proxmox-rest-server/src/worker_task.rs | 25 ++++++++++++++++++++-----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs
> index 643e1872..619b8e9d 100644
> --- a/proxmox-rest-server/src/worker_task.rs
> +++ b/proxmox-rest-server/src/worker_task.rs
> @@ -270,18 +270,33 @@ pub fn cleanup_old_tasks(compressed: bool) -> Result<(), Error> {
>          for i in 0..256 {
>              let mut path = setup.taskdir.clone();
>              path.push(format!("{:02X}", i));
> -            for file in std::fs::read_dir(path)? {
> -                let file = file?;
> +            let files = match std::fs::read_dir(path) {
> +                Ok(files) => files,
> +                Err(_) => continue, // does not exist or no permissions

hmm, silently ignoring ENOENT is one thing, but I'd not do so for other errors, at least
print a note/warning?

> +            };
> +            for file in files {
> +                let file = match file {
> +                    Ok(file) => file,
> +                    Err(err) => {
> +                        log::error!("task cleanup: could not check some file in {}: {}", i, err);
> +                        continue;
> +                    }
> +                };
>                  let path = file.path();
>  
> -                let modified = get_modified(file)
> -                    .map_err(|err| format_err!("error getting mtime for {:?}: {}", path, err))?;
> +                let modified = match get_modified(file) {
> +                    Ok(modified) => modified,
> +                    Err(err) => {
> +                        log::error!("task cleanup: error getting mtime for {:?}: {}", path, err);
> +                        continue;
> +                    }
> +                };
>  
>                  if modified < cutoff_time {
>                      match std::fs::remove_file(path) {
>                          Ok(()) => {},
>                          Err(err) if err.kind() == std::io::ErrorKind::NotFound => {},
> -                        Err(err) => bail!("could not remove file: {}", err),
> +                        Err(err) => log::error!("task cleanup: could not remove file: {}", err),
>                      }
>                  }
>              }





      reply	other threads:[~2022-03-28  6:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 12:38 Dominik Csapak
2022-03-28  6:30 ` Thomas Lamprecht [this message]

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=013ab17d-2ebf-aaca-0ce5-9eeabccba9c4@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=d.csapak@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 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