[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().
This commit is contained in:
Yueh-Hsuan Chiang 2024-03-27 09:43:38 -07:00 committed by GitHub
parent 9cd90751f0
commit 4b9e1e0ab3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 5 deletions

View File

@ -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(),
);
}
}
}
}