Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/AzimuthRPC.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down Expand Up @@ -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>();
string? line;
while ((line = reader.ReadLine()) is not null)
lines.Add(line);
return lines.ToArray();
}
}

Expand Down
Loading