This issue was solved with changeset r34846.
Usaku, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
io.c (io_fread, io_getpartial, rb_io_sysread): set buffer size
after check if readable, which can cause thread switch. [ruby-dev:45297][Bug #6099]
r, w = IO.pipe
r.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
buf = " " * 100
t = Thread.new{p r.readpartial(100, buf)}
sleep 0.1
Thread.pass
buf.replace("")
p buf.bytesize; w.write("a" * 100)
Thread.pass
t.join
IO#readpartial は
It blocks only if ios has no data immediately available.
The later means that readpartial is nonblocking-flag insensitive.
It blocks on the situation IO#sysread causes Errno::EWOULDBLOCK as if the fd is blocking mode.
などとある通り、r.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK) しても block することがあります。
よって、[BUG] が出たら明らかにおかしいんですが、そのコードが通ることを期待するのも間違っています。
It blocks only if ios has no data immediately available.
The later means that readpartial is nonblocking-flag insensitive.
It blocks on the situation IO#sysread causes Errno::EWOULDBLOCK as if the fd is blocking mode.
などとある通り、r.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK) しても block することがあります。
よって、[BUG] が出たら明らかにおかしいんですが、そのコードが通ることを期待するのも間違っています。