fix: handle temp file removal race condition in concurrent initializa… (#1185)
* fix: handle temp file removal race condition in concurrent initialization When multiple SQLPage instances start simultaneously in the same directory, they can encounter a race condition during initialization. The create_default_database() function creates a temporary file to test directory writability, then removes it. If multiple instances try to remove the same file concurrently, some panic with 'No such file or directory'. This commit replaces the .expect() panic with graceful error handling using if let Err(). The writability test has already succeeded by the time we try to remove the file, so whether another instance removed it is irrelevant. Includes a test that spawns 10 concurrent threads initializing AppConfig to verify no panics occur. ref #1183 * cargo fmt * the error may have another cause * Remove concurrent initialization test Removed the test for concurrent initialization. The test did not work --------- Co-authored-by: lovasoa <contact@ophir.dev>
This commit is contained in:
+3
-1
@@ -495,7 +495,9 @@ fn create_default_database(configuration_directory: &Path) -> String {
|
||||
default_db_path.display()
|
||||
);
|
||||
drop(tmp_file);
|
||||
std::fs::remove_file(&default_db_path).expect("removing temp file");
|
||||
if let Err(e) = std::fs::remove_file(&default_db_path) {
|
||||
log::debug!("Unable to remove temporary probe file. It might have already been removed by another instance started concurrently: {}", e);
|
||||
}
|
||||
return prefix + &encode_uri(&default_db_path) + "?mode=rwc";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user