7060790: (fs) FileSystem.newWatchService error message confusing when maximum inotify descriptors reached

Rémi Forax forax at univ-mlv.fr
Sat Aug 27 06:36:01 PDT 2011


On 08/27/2011 03:18 PM, Alan Bateman wrote:
>
> This is a minor tweak to the WatchService implementation on Linux so 
> that it prints a more useful message in the event that the system is 
> out of inotify instances. The errno when inotify_init fails in this 
> case is EMFILE and so the IOException is thrown with "Too many open 
> files" which can be confused with running out of file descriptors. The 
> patch simple translates this error into a more useful message to aid 
> diagnosing the issue. I don't propose to include a test with this as 
> tests that check exception message tend to be too fragile.
>
> Thanks,
> Alan.

Hi Alan,
patch looks good.

Rémi

>
>
> diff --git a/src/solaris/classes/sun/nio/fs/LinuxWatchService.java 
> b/src/solaris/classes/sun/nio/fs/LinuxWatchService.java
> --- a/src/solaris/classes/sun/nio/fs/LinuxWatchService.java
> +++ b/src/solaris/classes/sun/nio/fs/LinuxWatchService.java
> @@ -58,7 +58,10 @@ class LinuxWatchService
>         try {
>             ifd = inotifyInit();
>         } catch (UnixException x) {
> -            throw new IOException(x.errorString());
> +            String msg = (x.errno() == EMFILE) ?
> +                "User limit of inotify instances reached or too many 
> open files" :
> +                x.errorString();
> +            throw new IOException(msg);
>         }
>
>         // configure inotify to be non-blocking
> diff --git a/src/solaris/native/sun/nio/fs/genUnixConstants.c 
> b/src/solaris/native/sun/nio/fs/genUnixConstants.c
> --- a/src/solaris/native/sun/nio/fs/genUnixConstants.c
> +++ b/src/solaris/native/sun/nio/fs/genUnixConstants.c
> @@ -108,6 +108,7 @@ int main(int argc, const char* argv[]) {
>     DEF(EROFS);
>     DEF(ENODATA);
>     DEF(ERANGE);
> +    DEF(EMFILE);
>
>     // flags used with openat/unlinkat/etc.
> #if defined(AT_SYMLINK_NOFOLLOW) && defined(AT_REMOVEDIR)



More information about the nio-dev mailing list