Project

General

Profile

Actions

Bug #17415

closed

IO read gets blocked with Fiber Scheduler on Windows

Added by dsh0416 (Delton Ding) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0dev (2020-12-19 master 4735a5b9d2) [x64-mingw32]
[ruby-core:101582]

Description

Here is the given example code for reproduction the bug:

rd, wr = IO.pipe
scheduler = Evt::Scheduler.new # Any scheduler including the test scheduler in the ruby repo could reproduce the same problem.

message = nil
Fiber.set_scheduler scheduler

Fiber.schedule do
  wr.write(MESSAGE)
  wr.close
end
  
Fiber.schedule do
  message = rd.read(20)
  rd.close
end

scheduler.run

assert_equal MESSAGE, message
assert rd.closed?
assert wr.closed?

When running under Linux, FreeBSD or macOS, the code works fine. But when running under Windows:

#...

Fiber.schedule do
  message = rd.read(20) # !!! -> Got blocked here
  rd.close
end

#...

Since some of the files don't support non-blocking on Windows, I double checked with the following code:

a, b = IO.pipe
b.write_nonblock("Test")
a.read_nonblock(4) # => "Test"

which works totally fine on Windows. I suppose some kind of IO non-blocking setup is not working properly under Windows.

Still investigating the details for patching...

Actions #1

Updated by dsh0416 (Delton Ding) almost 2 years ago

  • ruby -v changed from ruby 3.0.0rc1 to ruby 3.0.0dev (2020-12-19 master 4735a5b9d2) [x64-mingw32]
Actions #2

Updated by dsh0416 (Delton Ding) almost 2 years ago

  • Subject changed from IO read blocking with Fiber Scheduler on Windows to IO read gets blocked with Fiber Scheduler on Windows

Updated by zverok (Victor Shepelev) almost 2 years ago

https://docs.ruby-lang.org/en/master/doc/scheduler_md.html#label-IO

By default, I/O is non-blocking. Not all operating systems support non-blocking I/O. Windows is a notable example where socket I/O can be non-blocking but pipe I/O is blocking.

Updated by dsh0416 (Delton Ding) almost 2 years ago

zverok (Victor Shepelev) wrote in #note-3:

https://docs.ruby-lang.org/en/master/doc/scheduler_md.html#label-IO

By default, I/O is non-blocking. Not all operating systems support non-blocking I/O. Windows is a notable example where socket I/O can be non-blocking but pipe I/O is blocking.

Ah. I tested it again with UDPSocket, and everything works fine. It looks like it is the problem mentioned in the scheduler docs. Thank you so much. I think we could close the issue.

Actions #5

Updated by jeremyevans0 (Jeremy Evans) almost 2 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF