question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: When WatchStaticMappings=true throws exceptions on updating the mapping files

See original GitHub issue

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:

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:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
StefHcommented, Jun 22, 2019

@muzammilkm Can you verify if this works?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found