Bug: When WatchStaticMappings=true throws exceptions on updating the mapping files
See original GitHub issueWhen 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:
Stopwatch sw = new Stopwatch();
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;
}
Refer for IsFileLocked Avoiding File Concurrency when using System.IO.FileSystemWatcher
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
Flutter firebase - can't catch exception thrown white trying ...
While trying to update a document in Firestore with a map with an empty key (a bug in my code), I wasn't able...
Read more >Exception Error Codes and Descriptions
Cause: The method used by the transformation mapping using a valueholder is invalid. This exception is thrown when OracleAS TopLink tries to access...
Read more >Common Hibernate Exceptions
Many conditions can cause exceptions to be thrown while using Hibernate. These can be mapping errors, infrastructure problems, SQL errors, ...
Read more >Best Practices for exceptions - .NET
Learn best practices for exceptions, such as using try/catch/finally, handling common conditions without exceptions, and using predefined .
Read more >How to Fix the Unsupported Operation Exception in Java
UnsupportedOperationException is a Java runtime exception that occurs when an unsupported operation is requested but could not be performed.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@muzammilkm Can you verify if this works?
https://github.com/WireMock-Net/WireMock.Net/pull/286