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:
Mukhtar
2026-01-12 11:43:19 +00:00
committed by GitHub
parent 8d106fb677
commit 5cf1882dc3
+3 -1
View File
@@ -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";
}
}