Home Dashboard Directory Help
Search

FileSystemWatcher overlapped listener raising an exception on malformed notifications by Luc Habert


Status: 

Active


6
0
Sign in
to vote
Type: Bug
ID: 780775
Opened: 3/6/2013 4:41:01 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

Our software uses a FileSystemWatcher. At a customer of our's, the watcher's listener systematically raises the following exception (caught through AppDomain.CurrentDomain.UnhandledException):

System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.GetFileName(String path)
at System.IO.FileSystemWatcher.MatchPattern(String relativePath)
at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(Int32 action, String name)
at System.IO.FileSystemWatcher.CompletionStatusChanged(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* overlappedPointer)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

I found out that the FILE_NOTIFY_INFORMATION structures received (and probably sent by their network file server which I know nothing about) are malformed: the FileNameLength includes the terminating null character, which, I guess, ends up in the path processed by CheckInvalidPathChars.

This is definitely a bug of the file server, but I think it wouldn't hurt if the file system watcher was a bit defensive with respect to the contents of the notifications. It's a very painful problem, because there is no way to catch the exception: it occurs in a filesystemwatcher listener called directly by .NET's guts. When we catch it in AppDomain.UnhandledException, all we can do is pop up a message explaining that our app is going to close.

Details
Sign in to post a comment.
Posted by Zaid Amir on 2/10/2014 at 3:06 AM
I noticed the same issue recently, and it seems to happen randomly. My trace is a bit different than the OP's:

at System.IO.Path.GetFileName(String path)
at System.IO.FileSystemWatcher.MatchPattern(String relativePath)
at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(Int32 action, String name)
at System.IO.FileSystemWatcher.CompletionStatusChanged(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* overlappedPointer)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

The trace does not reach "CheckInvalidPathChars" but it is indeed throwing an unhandled exception.
Posted by Luc Habert on 12/6/2013 at 3:50 AM
The cause of the error is a malformed notification (a filename length field counting the final null character when it should not). I have seen a file server systematically send such notifications (unfortunately, I couldn't get details on this server). I have also seen a few otherwise normal servers occasionally send one.

Possible workarounds:
- fix the server (easier said than done)
- provide a user option to stop using fs watchers (that's what we did)
- rewrite the FSWatcher class.
Posted by s.j.w.vreeken on 12/6/2013 at 3:24 AM
Is there any resolution for this issue. Since yesterday it is plaguing my software and I am unable to detect the cause of this error.
Posted by Werner van Deventer on 10/2/2013 at 9:52 PM
This issue affects my products as well. Unable to reproduce in testing environments but the live error logs show this happens at least twice a day in the wild. Exact same stack trace as highlighted in the body of this report.

In my opinion, this error should be caught internally and raise the Error event so that it can be handled by the caller instead of throwing the unhandled exception which is difficult to recover from.
Posted by Microsoft on 3/27/2013 at 11:12 AM
Thank you for your feedback. Unfortunately, we are not able to reproduce the issue. Thus, I'm resolving it as "Not Repro", but feel free to reactivate with more information.

Regards,
Immo Landwerth
.NET Framework team
Posted by Microsoft on 3/7/2013 at 1:06 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 3/6/2013 at 4:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.