Skip to content

Commit

Permalink
Fix shutdown hang related to files deletion
Browse files Browse the repository at this point in the history
This CL is moving the background tasks to "CONTINUE_ON_SHUTDOWN"
shutdown semantic.

If the deletion task has already started before the shutdown started,
it will be executed in low IO priority. This can lead to a really slow
files deletion and can cause shutdown hangs.

Since there is no need to be consistent on these files cleanup, the
shutdown hang can be avoided by letting the task running and not
blocking the shutdown.

R=lucnguyen@google.com, gab@chromium.org

Bug: 1428815
Change-Id: If6c3f40cc12f277de7a7aa49cac624364857c437
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4823246
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Reviewed-by: Luc Nguyen <lucnguyen@google.com>
Reviewed-by: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Reviewed-by: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1189682}
  • Loading branch information
bergeret authored and pull[bot] committed Feb 26, 2024
1 parent 4d9c6cc commit 1256502
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions components/metrics/persistent_histograms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,15 @@ void PersistentHistogramsCleanup(const base::FilePath& metrics_dir) {
base::Seconds(kSpareFileCreateDelaySeconds));

#if BUILDFLAG(IS_WIN)
// Post a best effort task that will delete files. Unlike SKIP_ON_SHUTDOWN,
// which will block on the deletion if the task already started,
// CONTINUE_ON_SHUTDOWN will not block shutdown on the task completing. It's
// not a *necessity* to delete the files the same session they are "detected".
// On shutdown, the deletion will be interrupted.
base::ThreadPool::PostDelayedTask(
FROM_HERE,
{base::MayBlock(), base::TaskPriority::LOWEST,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN},
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
base::BindOnce(&DeleteOldWindowsTempFiles, metrics_dir),
kDeleteOldWindowsTempFilesDelay);
#endif // BUILDFLAG(IS_WIN)
Expand Down

0 comments on commit 1256502

Please sign in to comment.