Skip to content

Commit

Permalink
Fixed NRE in FileExceptionlessLog
Browse files Browse the repository at this point in the history
The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Exceptionless.Logging.FileExceptionlessLog.Flush() in /Users/runner/work/Exceptionless.Net/Exceptionless.Net/src/Exceptionless/Logging/FileExceptionlessLog.cs:line 167
   at Exceptionless.Logging.FileExceptionlessLog.OnFlushTimer(Object state) in /Users/runner/work/Exceptionless.Net/Exceptionless.Net/src/Exceptionless/Logging/FileExceptionlessLog.cs:line 260
   at System.Threading.TimerQueueTimer.<>c.<.cctor>b__27_0(Object state)
  • Loading branch information
niemyjski committed May 18, 2023
1 parent fda1479 commit 3927be6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Exceptionless/Logging/FileExceptionlessLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void Flush() {
_isFlushing = true;

Run.WithRetries(() => {
if (!_flushMutex.WaitOne(TimeSpan.FromSeconds(5)))
if (_flushMutex == null || !_flushMutex.WaitOne(TimeSpan.FromSeconds(5)))
return;
hasFlushLock = true;
Expand All @@ -163,8 +163,11 @@ public void Flush() {
} catch (Exception ex) {
System.Diagnostics.Trace.WriteLine("Exceptionless: Error flushing log contents to disk: {0}", ex.ToString());
} finally {
if (hasFlushLock)
_flushMutex.ReleaseMutex();
if (hasFlushLock) {
// Ensure the mutex hasn't been disposed.
_flushMutex?.ReleaseMutex();
}

_isFlushing = false;
}
}
Expand Down Expand Up @@ -293,7 +296,7 @@ protected string GetLastLinesFromFile(int lines = 100) {
if (lineCount != lines)
continue;

var returnBuffer = new byte[fs.Value.Length - fs.Value.Position];
byte[] returnBuffer = new byte[fs.Value.Length - fs.Value.Position];
fs.Value.Read(returnBuffer, 0, returnBuffer.Length);

return Encoding.ASCII.GetString(returnBuffer);
Expand Down

0 comments on commit 3927be6

Please sign in to comment.