You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When WatchStaticMappings = true in settings throws exceptions & application abnormally gets aborted on updating the mapping files while Mock Server is running.
Exception:
System.IO.IOException: The process cannot access the file '' because it is being used by another process.
at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks)
at System.IO.File.InternalReadAllText(String path, Encoding encoding)
at System.IO.File.ReadAllText(String path)
at WireMock.Server.FluentMockServer.ReadStaticMappingAndAddOrUpdate(String path) in /Server/FluentMockServer.Admin.cs:line 217
at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(WatcherChangeTypes changeType, String name)
at System.IO.FileSystemWatcher.ParseEventBufferAndNotifyForEach(Byte[] buffer)
at System.IO.FileSystemWatcher.ReadDirectoryChangesCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* overlappedPointer)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
This happens due to editor lock duration while writing to disk(saving). I tried capturing the duration for various editors
VS Code: ~400 ms - ~100 ms
Sublime: ~250ms - ~100 ms
Notepad: ~50ms - ~10ms.
Finding the lock duration & work around for this issue, added in WireMock.Net\Server\FluentMockServer.Admin.cs in ReadStaticMappingAndAddOrUpdate method at line 215:
Stopwatchsw=newStopwatch();sw.Start();while(IsFileLocked(path)&&sw.ElapsedMilliseconds<EnhancedFileSystemWatcherTimeoutMs){}sw.Stop();_logger.Debg("Waited for {0} ms",sw.ElapsedMilliseconds);if(sw.ElapsedMilliseconds>EnhancedFileSystemWatcherTimeoutMs){_logger.Error("Abort. waited for {0} ms",sw.ElapsedMilliseconds);return;}
When WatchStaticMappings = true in settings throws exceptions & application abnormally gets aborted on updating the mapping files while Mock Server is running.
Exception:
This happens due to editor lock duration while writing to disk(saving). I tried capturing the duration for various editors
VS Code: ~400 ms - ~100 ms
Sublime: ~250ms - ~100 ms
Notepad: ~50ms - ~10ms.
Finding the lock duration & work around for this issue, added in WireMock.Net\Server\FluentMockServer.Admin.cs in ReadStaticMappingAndAddOrUpdate method at line 215:
Refer for IsFileLocked
Avoiding File Concurrency when using System.IO.FileSystemWatcher
The text was updated successfully, but these errors were encountered: