From 2e2b324e7235672d8053502b2ded654767db8784 Mon Sep 17 00:00:00 2001 From: Refil <53364591+Refilewski@users.noreply.github.com> Date: Sun, 18 Oct 2026 23:17:46 +0200 Subject: [PATCH] fix: read live logs with compatible FileShare flags and smoke regression --- src/AzimuthRPC.App/Program.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/AzimuthRPC.App/Program.cs b/src/AzimuthRPC.App/Program.cs index 68d0405..5708832 100644 --- a/src/AzimuthRPC.App/Program.cs +++ b/src/AzimuthRPC.App/Program.cs @@ -42,6 +42,12 @@ private static void Main(string[] args) log.Write($"AzimuthRPC {VersionInfo.Version} standalone started{(smokeTest ? " (smoke test)" : string.Empty)}"); log.Write($"Log file: {log.FilePath}"); + // Regression: open a read handle while the logger still owns its + // write handle. This must work without closing or pausing logging. + if (smokeTest && !log.ReadSupportLines().Any(line => + line.Contains("standalone started (smoke test)", StringComparison.Ordinal))) + throw new IOException("Live log snapshot read failed during smoke test."); + if (log.FallbackReason is string fallbackReason) { log.Write($"Primary log unavailable: {fallbackReason}"); @@ -321,7 +327,19 @@ internal string[] ReadSupportLines() lock (_gate) { _writer.Flush(); - return File.ReadAllLines(FilePath); + + // File.ReadAllLines uses FileShare.Read, which conflicts with our + // still-open FileAccess.Write handle. Explicitly allow other readers, + // writers and delete/rotation while taking this snapshot. + using var stream = new FileStream( + FilePath, FileMode.Open, FileAccess.Read, + FileShare.ReadWrite | FileShare.Delete); + using var reader = new StreamReader(stream); + var lines = new List(); + string? line; + while ((line = reader.ReadLine()) is not null) + lines.Add(line); + return lines.ToArray(); } }