Skip to content

Using File.read with async in Windows causes Bad file descriptor Exception #206

Open

Description

@phenylshima

Description

When I use File.read in Async, the following exception is thrown.

require "async"

Async do |task|
  task.async do
    p File.read("README.md")
  end
end
  0.0s     warn: Async::Task [oid=0x348] [ec=0x35c] [pid=4880] [2022-12-06 13:02:07 +0900]
               | Task may have ended with unhandled exception.
               |   Errno::EBADF: Bad file descriptor
               |   → <internal:io> 63
               |     C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/io-event-1.1.3/lib/io/event/selector/select.rb 206

This behavior is only observed in Windows with ruby 3.1.

Also, I reproduced this behavior in GitHub Actions here.

Sample Code

require "async"

Async do |task|
  task.async do
    p File.read("README.md")
  end
end

Expected Behavior

No exception is thrown, and the content of README.md is shown on console.

Actual Behavior

Errno::EBADF: Bad file descriptor exception is thrown, and the task stops there.

Versions

Windows 10 Home 21H2
ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x64-mingw-ucrt]
async (2.3.0)

Activity

  1. ioquatix commented on Dec 6, 2022

    @ioquatix
    Member

    I guess it's a limitation of Windows. The best thing we can do is try to avoid doing any kind of asynchronous file IO, which isn't supported anyway in this situation. The simple solution is to just detect windows and skip any kind of asynchronous io_read and io_write operations.

  2. phenylshima commented on Dec 6, 2022

    @phenylshima
    Author

    Then I'll just try detecting Windows and avoid async file IO on it...

    Thank you for your comment and advice.
    I'm closing this issue.

  3. ioquatix commented on Dec 6, 2022

    @ioquatix
    Member

    Async on Windows is a work in progress. The first part was to get io-event working which is tested, but async itself is not well tested on Windows yet. We should probably disable the io_read and io_write hooks on Windows for this reason. I want to leave this issue open until we do that.

  4. ioquatix commented on Dec 6, 2022

    @ioquatix
    Member

    #184 now includes the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions