Skip to content

Commit 5cf1882

Browse files
mukhtaroniflovasoa
andauthored
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>
1 parent 8d106fb commit 5cf1882

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/app_config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ fn create_default_database(configuration_directory: &Path) -> String {
495495
default_db_path.display()
496496
);
497497
drop(tmp_file);
498-
std::fs::remove_file(&default_db_path).expect("removing temp file");
498+
if let Err(e) = std::fs::remove_file(&default_db_path) {
499+
log::debug!("Unable to remove temporary probe file. It might have already been removed by another instance started concurrently: {}", e);
500+
}
499501
return prefix + &encode_uri(&default_db_path) + "?mode=rwc";
500502
}
501503
}

0 commit comments

Comments
 (0)