connamara / quickfixn

QuickFIX/n implements the FIX protocol on .NET.
http://quickfixn.org
Other
479 stars 562 forks source link

throw IOException: The process cannot access the file 'xxxx\log\Non-Session-Log.messages.current.log' because it is being used by another process. #891

Open VAllens opened 2 months ago

VAllens commented 2 months ago

Unit test execution of ThreadedSocketAcceptorTests fails, where TestRecreation method execution throws an IOException with the exception message: The process cannot access the file 'xxxx\log\Non-Session-Log.messages.current.log' because it is being used by another process.

D:\repo\quickfixn>cd UnitTests

D:\repo\quickfixn\UnitTests>dotnet test -c Release
  Determining projects to restore...
  All projects are up-to-date for restore.
  QuickFix -> D:\repo\quickfixn\QuickFIXn\bin\Release\net8.0\QuickFix.dll
  QuickFix.FIX50 -> D:\repo\quickfixn\Messages\FIX50\bin\Release\net8.0\QuickFix.FIX50.dll
  QuickFix.FIX50SP2 -> D:\repo\quickfixn\Messages\FIX50SP2\bin\Release\net8.0\QuickFix.FIX50SP2.
  dll
  QuickFix.FIX42 -> D:\repo\quickfixn\Messages\FIX42\bin\Release\net8.0\QuickFix.FIX42.dll
  QuickFix.FIX40 -> D:\repo\quickfixn\Messages\FIX40\bin\Release\net8.0\QuickFix.FIX40.dll
  QuickFix.FIXT11 -> D:\repo\quickfixn\Messages\FIXT11\bin\Release\net8.0\QuickFix.FIXT11.dll
  QuickFix.FIX50SP1 -> D:\repo\quickfixn\Messages\FIX50SP1\bin\Release\net8.0\QuickFix.FIX50SP1.
  dll
  QuickFix.FIX44 -> D:\repo\quickfixn\Messages\FIX44\bin\Release\net8.0\QuickFix.FIX44.dll
  QuickFix.FIX43 -> D:\repo\quickfixn\Messages\FIX43\bin\Release\net8.0\QuickFix.FIX43.dll
  QuickFix.FIX41 -> D:\repo\quickfixn\Messages\FIX41\bin\Release\net8.0\QuickFix.FIX41.dll
  UnitTests -> D:\repo\quickfixn\UnitTests\bin\Release\net8.0\UnitTests.dll
Test run for D:\repo\quickfixn\UnitTests\bin\Release\net8.0\UnitTests.dll (.NETCoreApp,Version=v8.0)
VSTest version 17.11.0 (x64)

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Unhandled exception. System.IO.IOException: The process cannot access the file 'D:\repo\quickfixn\UnitTests\bin\Release\net8.0\log\Non-Session-Log.messages.current.log' because it is being used by another process.
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.StreamWriter..ctor(String path, Boolean append)
   at QuickFix.Logger.FileLog..ctor(String fileLogPath, SessionID sessionId) in D:\repo\quickfixn\QuickFIXn\Logger\FileLog.cs:line 40
   at QuickFix.Logger.FileLogFactory.CreateNonSessionLog() in D:\repo\quickfixn\QuickFIXn\Logger\FileLogFactory.cs:line 26
   at QuickFix.Logger.NonSessionLog.OnEvent(String s) in D:\repo\quickfixn\QuickFIXn\Logger\NonSessionLog.cs:line 20
   at QuickFix.Transport.SocketInitiator.LogThreadStartConnectionFailed(SocketInitiatorThread t, Exception e) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 82
   at QuickFix.Transport.SocketInitiator.SocketInitiatorThreadStart(Object socketInitiatorThread) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 71
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
Unhandled exception. System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'FileLog'.
   at QuickFix.Logger.FileLog.DisposedCheck() in D:\repo\quickfixn\QuickFIXn\Logger\FileLog.cs:line 70
   at QuickFix.Logger.FileLog.OnEvent(String s) in D:\repo\quickfixn\QuickFIXn\Logger\FileLog.cs:line 114
   at QuickFix.Transport.SocketInitiator.LogThreadStartConnectionFailed(SocketInitiatorThread t, Exception e) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 85
   at QuickFix.Transport.SocketInitiator.SocketInitiatorThreadStart(Object socketInitiatorThread) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 71
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
Unhandled exception. System.IO.IOException: The process cannot access the file 'D:\repo\quickfixn\UnitTests\bin\Release\net8.0\log\Non-Session-Log.messages.current.log' because it is being used by another process.
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.StreamWriter..ctor(String path, Boolean append)
   at QuickFix.Logger.FileLog..ctor(String fileLogPath, SessionID sessionId) in D:\repo\quickfixn\QuickFIXn\Logger\FileLog.cs:line 40
   at QuickFix.Logger.FileLogFactory.CreateNonSessionLog() in D:\repo\quickfixn\QuickFIXn\Logger\FileLogFactory.cs:line 26
   at QuickFix.Logger.NonSessionLog.OnEvent(String s) in D:\repo\quickfixn\QuickFIXn\Logger\NonSessionLog.cs:line 20
   at QuickFix.Transport.SocketInitiator.LogThreadStartConnectionFailed(SocketInitiatorThread t, Exception e) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 82
   at QuickFix.Transport.SocketInitiator.SocketInitiatorThreadStart(Object socketInitiatorThread) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 71
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.IO.IOException: The process cannot access the file 'D:\repo\quickfixn\UnitTests\bin\Release\net8.0\log\Non-Session-Log.messages.current.log' because it is being used by another process.
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.StreamWriter..ctor(String path, Boolean append)
   at QuickFix.Logger.FileLog..ctor(String fileLogPath, SessionID sessionId) in D:\repo\quickfixn\QuickFIXn\Logger\FileLog.cs:line 40
   at QuickFix.Logger.FileLogFactory.CreateNonSessionLog() in D:\repo\quickfixn\QuickFIXn\Logger\FileLogFactory.cs:line 26
   at QuickFix.Logger.NonSessionLog.OnEvent(String s) in D:\repo\quickfixn\QuickFIXn\Logger\NonSessionLog.cs:line 20
   at QuickFix.Transport.SocketInitiator.LogThreadStartConnectionFailed(SocketInitiatorThread t, Exception e) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 82
   at QuickFix.Transport.SocketInitiator.SocketInitiatorThreadStart(Object socketInitiatorThread) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 71
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
Unhandled exception. System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'FileLog'.
   at QuickFix.Logger.FileLog.DisposedCheck() in D:\repo\quickfixn\QuickFIXn\Logger\FileLog.cs:line 70
   at QuickFix.Logger.FileLog.OnEvent(String s) in D:\repo\quickfixn\QuickFIXn\Logger\FileLog.cs:line 114
   at QuickFix.Transport.SocketInitiator.LogThreadStartConnectionFailed(SocketInitiatorThread t, Exception e) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 85
   at QuickFix.Transport.SocketInitiator.SocketInitiatorThreadStart(Object socketInitiatorThread) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 71
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
Unhandled exception. System.IO.IOException: The process cannot access the file 'D:\repo\quickfixn\UnitTests\bin\Release\net8.0\log\Non-Session-Log.messages.current.log' because it is being used by another process.
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.StreamWriter..ctor(String path, Boolean append)
   at QuickFix.Logger.FileLog..ctor(String fileLogPath, SessionID sessionId) in D:\repo\quickfixn\QuickFIXn\Logger\FileLog.cs:line 40
   at QuickFix.Logger.FileLogFactory.CreateNonSessionLog() in D:\repo\quickfixn\QuickFIXn\Logger\FileLogFactory.cs:line 26
   at QuickFix.Logger.NonSessionLog.OnEvent(String s) in D:\repo\quickfixn\QuickFIXn\Logger\NonSessionLog.cs:line 20
   at QuickFix.Transport.SocketInitiator.LogThreadStartConnectionFailed(SocketInitiatorThread t, Exception e) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 82
   at QuickFix.Transport.SocketInitiator.SocketInitiatorThreadStart(Object socketInitiatorThread) in D:\repo\quickfixn\QuickFIXn\Transport\SocketInitiator.cs:line 71
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

Passed!  - Failed:     0, Passed:   195, Skipped:     0, Total:   195, Duration: 6 s - UnitTests.dll (net8.0)
Test Run Aborted.

Workload updates are available. Run `dotnet workload list` for more information.
VAllens commented 2 months ago

I committed a pull request to fix this issue: https://github.com/connamara/quickfixn/pull/890

gbirchmeier commented 2 months ago

Does this fail consistently?

I usually do my dev on a Mac, maybe that's why I haven't observed it.

gbirchmeier commented 2 months ago

Yep, I just ran it on windows and it failed. Argh.

VAllens commented 1 month ago

Does this fail consistently?

I usually do my dev on a Mac, maybe that's why I haven't observed it.

Yes, always a failure.