diff --git a/QuickFIXn/Logger/NonSessionLog.cs b/QuickFIXn/Logger/NonSessionLog.cs index 3cc0d6bc9..5e369c863 100644 --- a/QuickFIXn/Logger/NonSessionLog.cs +++ b/QuickFIXn/Logger/NonSessionLog.cs @@ -4,7 +4,7 @@ namespace QuickFix.Logger; /// A logger that can be used when the calling logic cannot identify a session (which is rare). /// Does not create a file until first write. /// -public class NonSessionLog { +public class NonSessionLog : System.IDisposable { private readonly ILogFactory _logFactory; private ILog? _log; @@ -16,10 +16,23 @@ internal NonSessionLog(ILogFactory logFactory) { } internal void OnEvent(string s) { + if (_disposed) return; + lock (_sync) { _log ??= _logFactory.CreateNonSessionLog(); } - _log.OnEvent(s); + _log?.OnEvent(s); + } + + private bool _disposed; + public void Dispose() { + if (_disposed) return; + + if (_log != null) { + _log.Dispose(); + _log = null; + _disposed = true; + } } } diff --git a/QuickFIXn/ThreadedSocketAcceptor.cs b/QuickFIXn/ThreadedSocketAcceptor.cs index 840300aab..2f3e69daf 100755 --- a/QuickFIXn/ThreadedSocketAcceptor.cs +++ b/QuickFIXn/ThreadedSocketAcceptor.cs @@ -274,6 +274,8 @@ public void Stop(bool force) LogoutAllSessions(force); DisposeSessions(); _sessions.Clear(); + _nonSessionLog.Dispose(); + _isStarted = false; // FIXME StopSessionTimer(); // FIXME Session.UnregisterSessions(GetSessions()); diff --git a/UnitTests/ThreadedSocketReactorTests.cs b/UnitTests/ThreadedSocketReactorTests.cs index cc9ad0505..f096bc703 100644 --- a/UnitTests/ThreadedSocketReactorTests.cs +++ b/UnitTests/ThreadedSocketReactorTests.cs @@ -55,7 +55,7 @@ public void TestStartOnBusyPort() var ex = Assert.Throws(delegate { testingObject.Run(); })!; StringAssert.StartsWith(" Error starting listener:", stdOut.ToString()); - StringAssert.StartsWith("Address already in use", ex.Message); + Assert.That(ex.SocketErrorCode, Is.EqualTo(SocketError.AddressAlreadyInUse)); } [TearDown]