Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around EPERM fstat error for inotify under WSL #6535

Merged
merged 4 commits into from Feb 10, 2021

Conversation

headius
Copy link
Member

@headius headius commented Jan 15, 2021

The fstat system call raises EPERM when run against an inotify file descriptor under Windows Subsystem for Linux, as reported in #6129.

Rails uses inotify support via rb-inotify, which recently started using IO.new to wrap the inotify file descriptor. Our logic for IO.new tries to use fstat in two places, which causes rb-inotify to fail.

There are updates to WSL that purport to improve inotify support, but I have been unable to find a rig that works properly.

This PR makes the following changes in an attempt to deal with the issue:

  • When checking for fd liveness in FilenoUtil, we prefer fcntl except on Windows (which only has fstat). This means we use fcntl under WSL, avoiding the EPERM.
  • Ignore any exception raised when using fstat to determine the file type, which we do to skip using selection logic against normal files. The logic I added assumes if we can't fstat it is probably not a normal file.

The second fix is mildly hacky but our fstat there was already hacky.

This allows the reduced script from #6129 to run properly and may fix #6129 sufficiently well.

The file descriptor created by inotify fails to fstat when running
inside the Windows Subsystem for Linux, resulting in an EPERM and
breaking JRuby on Rails apps that are using rb-inotify. This patch
mimics the CRuby code in preferring fcntl over fstat.

Since we cannot easily detect the availability of fcntl, this
logic just falls back to fstat for the one platform where we know
we can't use fcntl: Windows.

Fixes jruby#6129.
@headius headius added this to the JRuby 9.3.0.0 milestone Jan 15, 2021
@headius
Copy link
Member Author

headius commented Feb 8, 2021

Bit of an issue with this fix in that it swallows errors when attempting to IO.new against a closed or invalid descriptor.

@headius
Copy link
Member Author

headius commented Feb 8, 2021

It might be sufficient to reduce the exception-swallowing catch to just the EPERM we see in WSL, since that would allow EBADF and friends through for bad descriptors and EPERM is not an expected error from fstat.

EPERM has only been osbserved here when calling fstat against an
inotify file descriptor under Windows Subsystem for Linux. Because
this is not otherwise expected as an error from fstat, we assume
it means this is not a normal file.
@headius headius merged commit 5d4dcf8 into jruby:master Feb 10, 2021
@headius headius deleted the io_new_use_fcntl branch February 10, 2021 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trouble when running 'rails server' in WSL
1 participant