From 5cf1882dc3fa96197f31320ecbe79e805dbf5b8d Mon Sep 17 00:00:00 2001 From: Mukhtar <72737041+mukhtaronif@users.noreply.github.com> Date: Mon, 12 Jan 2026 11:43:19 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20handle=20temp=20file=20removal=20race=20?= =?UTF-8?q?condition=20in=20concurrent=20initializa=E2=80=A6=20(#1185)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- src/app_config.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app_config.rs b/src/app_config.rs index d4532c5b..b28150ca 100644 --- a/src/app_config.rs +++ b/src/app_config.rs @@ -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"; } }