Skip to content

Commit

Permalink
fix: be more lenient about temporary read failures of the log file
Browse files Browse the repository at this point in the history
Fixes #4559.
  • Loading branch information
beheh committed Sep 5, 2024
1 parent cf98ffd commit 2287d84
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion HearthWatcher/LogReader/LogFileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,11 @@ private void ReadLogFile()
_logFileExists = true;
OnLogFileFound?.Invoke(Info.Name);
}
using(var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))

FileStream? fs = null;
try
{
fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
fs.Seek(_offset, SeekOrigin.Begin);
if(fs.Length == _offset)
{
Expand Down Expand Up @@ -234,6 +237,17 @@ private void ReadLogFile()
}
}
}
catch {
// some kind of error - maybe the log file has disappeared?
// stick around until somebody calls Stop()
Thread.Sleep(LogWatcher.UpdateDelay);
continue;
}
finally
{
if(fs is IDisposable dispose)
dispose.Dispose();
}
}
Thread.Sleep(LogWatcher.UpdateDelay);
}
Expand Down

0 comments on commit 2287d84

Please sign in to comment.