From e0fcbaab2fd70febdf4d810d344a413002d7c12c Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Thu, 27 Jul 2023 22:17:00 +0100 Subject: [PATCH] Fix race condition with duplicate instances turns out it happens so quickly that not even having a file existence check right before opening it is sufficient enough --- Bloxstrap/Logger.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Bloxstrap/Logger.cs b/Bloxstrap/Logger.cs index 45581be..b2760a1 100644 --- a/Bloxstrap/Logger.cs +++ b/Bloxstrap/Logger.cs @@ -36,7 +36,15 @@ return; } - _filestream = File.Open(location, FileMode.Create, FileAccess.Write, FileShare.Read); + try + { + _filestream = File.Open(location, FileMode.Create, FileAccess.Write, FileShare.Read); + } + catch (IOException) + { + WriteLine(LOG_IDENT, "Failed to initialize because log file already exists"); + } + Initialized = true;