Bug
In Logger.Log, the _writer null check is performed before acquiring the lock, but _writer is used inside the lock without re-checking:
if (_writer == null) return; // Check outside lock
lock (_lock)
{
_writer.WriteLine(logEntry); // Could be null if Shutdown() ran concurrently
}
If Shutdown() is called between the null check and the lock acquisition, _writer becomes null, leading to a NullReferenceException.
Impact
Race condition during service shutdown that could cause an unhandled exception and mask the real shutdown reason in logs.
Suggested fix
Re-check _writer inside the lock:
lock (_lock)
{
if (_writer == null) return;
_writer.WriteLine(logEntry);
}
File
src/Servy.Core/Logging/Logger.cs — lines 232-234
Bug
In
Logger.Log, the_writernull check is performed before acquiring the lock, but_writeris used inside the lock without re-checking:If
Shutdown()is called between the null check and the lock acquisition,_writerbecomes null, leading to aNullReferenceException.Impact
Race condition during service shutdown that could cause an unhandled exception and mask the real shutdown reason in logs.
Suggested fix
Re-check
_writerinside the lock:File
src/Servy.Core/Logging/Logger.cs— lines 232-234