From 6e97a5929e25cd180f58f57c15e7cc825176441d Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Thu, 1 Feb 2024 16:10:01 +1300 Subject: [PATCH] Don't enable `io_write` hook on Ruby < 3.3.1 as it's buggy. (#303) --- .github/workflows/coverage.yaml | 3 +++ lib/async/scheduler.rb | 2 +- test/io.rb | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 73f5fe9..83a98ff 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -29,6 +29,9 @@ jobs: - os: ubuntu ruby: "3.3" selector: URing + - os: ubuntu + ruby: "head" + selector: URing steps: - uses: actions/checkout@v4 diff --git a/lib/async/scheduler.rb b/lib/async/scheduler.rb index 05f4395..75e18c1 100644 --- a/lib/async/scheduler.rb +++ b/lib/async/scheduler.rb @@ -212,7 +212,7 @@ def io_read(io, buffer, length, offset = 0) timer&.cancel end - if RUBY_ENGINE != "ruby" || RUBY_VERSION >= "3.3.0" + if RUBY_ENGINE != "ruby" || RUBY_VERSION >= "3.3.1" def io_write(io, buffer, length, offset = 0) fiber = Fiber.current diff --git a/test/io.rb b/test/io.rb index 1101627..7c6ec5c 100644 --- a/test/io.rb +++ b/test/io.rb @@ -74,4 +74,18 @@ expect(input.wait_readable(0)).to be_nil end end + + describe '/dev/null' do + # Ruby < 3.3.1 will fail this test with the `io_write` scheduler hook enabled, as it will try to io_wait on /dev/null which will fail on some platforms (kqueue). + it "can write to /dev/null" do + out = File.open("/dev/null", "w") + + # Needs to write about 8,192 bytes to trigger the internal flush: + 1000.times do + out.puts "Hello World!" + end + ensure + out.close + end + end end