JDK-8014394 : (fs) WatchService failing when watching \\server\$d
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-05-11
  • Updated: 2014-11-17
  • Resolved: 2013-05-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u60Fixed 8 b93Fixed
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_21 " 
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
Windows 2008 R2 Standard sp1

EXTRA RELEVANT SYSTEM CONFIGURATION :
I've tested the program http://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java on several servers, both physical and virtual, domain members and standalone with the same result. All most probably have a few things in common (install media, antivirus software, etc).

A DESCRIPTION OF THE PROBLEM :
* Download http://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java
* Compile WatchDir.java
* Execute: java WatchDir c:\ <= Works
* Execute java WatchDir d:\ <= Works
* Execute java WatchDir \\<name_of_host>\c$ <= Works
* Execute java WatchDir \\<name_of_host>\d$ <= Doesn't work
* Create directory c:\temp\c and share as c
* Create directory d:\temp\d and share as c
* Execute java WatchDir \\<name_of_host>\c <= Works
* Execute java WatchDir \\<name_of_host>\c <= Doesnt work
This also goes for shares on remote hosts. Shares on the c:\ drive works, shares on other drives doesn't work.

Whe WatchDir doesn't work it silently exists after less than a seconds as key.reset(); returns false.

I can find no obvious reason for this when looking at the network traffic with WireShark. What I see is that when accessing \\..\c$ a  " Notify Request File: "  package is sent. This package is not sent when accessing \\...\d$.

A Powershell Filesystemwatcher program does not have the same problem. The Java developer developing some software for us has not been able to reproduce this behaviour on their system.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
* Install Windows 2008 R2 sp1
* Install jdk 1.7.0_21-b11
* Downoad and compile http://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java
* Execute java WatchDir \\<name_of_host>\c$ <= Works
* Execute java WatchDir \\<name_of_host>\d$ <= Exits in less than a second

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
WatchDir should work in the same way both for shares on c:\ and for shares on d:\.
ACTUAL -
WatchDir works with file shares on c:\, but not with file shares on d:\ (or other drives).

ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error messages.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
http://docs.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Implement an old fashioned file polling object.
Comments
Verified by manual execute WatchDir.java
26-07-2013

Normalized manual test as NB project is in the attachment (JDK-8014394.zip). The share test uses localhost and secondary disk. The issue does not happen with primary shared disk (\\localhost\c$). That is MS magic.
27-05-2013

For resource like [\\localhost\j$] we got [STATUS_MORE_PROCESSING_REQUIRED:=:ERROR_MORE_DATA] status on the [GetQueuedCompletionStatus] call. That is normal: http://stackoverflow.com/questions/3130785/when-are-io-completion-port-packets-sent-and-when-not , but need additional treatment.
20-05-2013

Perfect blog record about the related problem. http://qualapps.blogspot.com/2010/05/understanding-readdirectorychangesw_19.html "ReadDirectoryChangesW fails with ERROR_INVALID_PARAMETER when the buffer length is greater than 64 KB and the application is monitoring a directory over the network. This is due to a packet size limitation with the underlying file sharing protocols."
20-05-2013

The WatchService implementation on Windows uses ReadDirectoryChangesW. From the description it sounds like this is failing asynchronously and this is causing the key is canceled (which is the right behavior for this case). Unfortunately the API doesn't have the ability to report back errors after the registration has completed so it will need more investigation to understand why it is failing in the submitter environment.
13-05-2013