Friday, April 30, 2010

ReadDirectoryChangesW returns ERROR_BAD_NET_RESP (error code 58)


A recent project is about folder monitoring. The folder can be on a local hard drive or a network. We use the standard win32 api call: ReadDirectoryChangesW.
The function works perfectly on a remote WinNT system but occasionally fails on mornitoring a folder in a remote Unix system. At the beginning we suspect if a correct (or high enough) version of samba is install on that Unix machine, but confirmation is positive. Besides the function call does not fail consistently, which really bothers us. However, the last error code from ReadDirectoryChangesW is always 58 – ERROR_BAD_NET_RESP (The specified server cannot perform the requested operation).
I suspect it is an unsupported isssue, the latest Samba patch does not full support ReadDirectoryChangesW yet. There are few articles can be found from google, links:
The solution
The loop to check ReadDirectoryChangesW does not break if last error is ERROR_BAD_NET_RESP, continue process directory changes if it fails. The interesting thing is the next ReadDirectoryChangesW call could succeed following previous failure. So eventually we capture the directory changes and process it approprietly.
The ideal solution is a samba fully support ReadDirectoryChangesW

1 comments:

alexbk66 said...

Hi, I get the same problem, but even if I continue calling ReadDirectoryChangesW after receiving ERROR_BAD_NET_RESP - eventually notifications just stop.
But I found that if the lenght of the file name (incl. extension) doesn't change, i.e. if just the extension is changed - it works fine.
But it's really dodgy...