From 4b9e1e0ab3a2c6904729fc287fbce446d2a4e72c Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang <93241502+yhchiang-sol@users.noreply.github.com> Date: Wed, 27 Mar 2024 09:43:38 -0700 Subject: [PATCH] [TieredStorage] Exclude NotFound in reporting storage leakage on drop() (#446) #### Problem TieredStorage::drop() currently panic when it fails to delete the underlying file to raise awareness of possible storage resource leakage, including io::ErrorKind::NotFound. But sometimes the TieredStorage (or AccountsFile in general) instance is created then dropped without any file being created. This causes some false-alarms including unit-tests. #### Summary of Changes This PR excludes NotFound in reporting storage leakage on TieredStorage::drop(). --- accounts-db/src/tiered_storage.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/accounts-db/src/tiered_storage.rs b/accounts-db/src/tiered_storage.rs index cbca5c93d0041e..7b8b26fce64fa9 100644 --- a/accounts-db/src/tiered_storage.rs +++ b/accounts-db/src/tiered_storage.rs @@ -27,7 +27,7 @@ use { solana_sdk::account::ReadableAccount, std::{ borrow::Borrow, - fs, + fs, io, path::{Path, PathBuf}, sync::{ atomic::{AtomicBool, Ordering}, @@ -65,10 +65,14 @@ pub struct TieredStorage { impl Drop for TieredStorage { fn drop(&mut self) { if let Err(err) = fs::remove_file(&self.path) { - panic!( - "TieredStorage failed to remove backing storage file '{}': {err}", - self.path.display(), - ); + // Here we bypass NotFound error as the focus of the panic is to + // detect any leakage of storage resource. + if err.kind() != io::ErrorKind::NotFound { + panic!( + "TieredStorage failed to remove backing storage file '{}': {err}", + self.path.display(), + ); + } } } }