Skip to content

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

@phenylshima

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions