Skip to content

Commit 3927be6

Browse files
committed
Fixed NRE in FileExceptionlessLog
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)
1 parent fda1479 commit 3927be6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Exceptionless/Logging/FileExceptionlessLog.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void Flush() {
138138
_isFlushing = true;
139139

140140
Run.WithRetries(() => {
141-
if (!_flushMutex.WaitOne(TimeSpan.FromSeconds(5)))
141+
if (_flushMutex == null || !_flushMutex.WaitOne(TimeSpan.FromSeconds(5)))
142142
return;
143143

144144
hasFlushLock = true;
@@ -163,8 +163,11 @@ public void Flush() {
163163
} catch (Exception ex) {
164164
System.Diagnostics.Trace.WriteLine("Exceptionless: Error flushing log contents to disk: {0}", ex.ToString());
165165
} finally {
166-
if (hasFlushLock)
167-
_flushMutex.ReleaseMutex();
166+
if (hasFlushLock) {
167+
// Ensure the mutex hasn't been disposed.
168+
_flushMutex?.ReleaseMutex();
169+
}
170+
168171
_isFlushing = false;
169172
}
170173
}
@@ -293,7 +296,7 @@ protected string GetLastLinesFromFile(int lines = 100) {
293296
if (lineCount != lines)
294297
continue;
295298

296-
var returnBuffer = new byte[fs.Value.Length - fs.Value.Position];
299+
byte[] returnBuffer = new byte[fs.Value.Length - fs.Value.Position];
297300
fs.Value.Read(returnBuffer, 0, returnBuffer.Length);
298301

299302
return Encoding.ASCII.GetString(returnBuffer);

0 commit comments

Comments
 (0)