Add IO#timeout attribute and use it for blocking IO operations.#5653
Add IO#timeout attribute and use it for blocking IO operations.#5653ioquatix merged 6 commits intoruby:masterfrom
Conversation
7c695e8 to
8f5a57e
Compare
1145393 to
5509ca0
Compare
e1be1c4 to
28890f0
Compare
1b6a908 to
4070940
Compare
5212173 to
2361573
Compare
|
Consider the backward compatibility of ruby/openssl. |
2f8b0df to
2e57446
Compare
6438434 to
32e1a4f
Compare
|
|
||
| /** | ||
| * Set the timeout associated with the specified io object. This timeout is | ||
| * used as a best effort timeout to prevent operations from blocking forever. |
There was a problem hiding this comment.
I recommend to denote examples like "socket read/write".
There was a problem hiding this comment.
ah, it's not a description for the method.
There was a problem hiding this comment.
Sorry, I don't fully understand your feedback, but I'm happy to improve the documentation.
|
I have a follow up PR to improve the usage for backwards compatible extensions: #6507 |
|
Update to openssl gem: ruby/openssl#547 |
| end | ||
|
|
||
| ruby_version_is "3.0" do | ||
| ruby_version_is "3.0"..."3.1" do |
There was a problem hiding this comment.
Should have been ..."3.2", fixed in ruby/spec@c3677cf
| specified timeout. [[Feature #18630]] | ||
|
|
||
| ```ruby | ||
| STDIN.timeout = 1 |
There was a problem hiding this comment.
Sorry for asking here, but I'm reluctant to post a bug on Ruby Redmine. Should this feature work on all IO, like File and IO.fd_for(some_readiness_fd)? Because for me it doesn't.
require 'io/wait'
require 'socket'
require 'async'
begin
STDIN.timeout = 1
STDIN.read
rescue IO::TimeoutError
puts "IO#timeout= worked on STDIN"
end
begin
r, w = UNIXSocket.pair
r.timeout = 1
r.read
rescue IO::TimeoutError
puts "IO#timeout= worked on UNIXSocket"
else
puts "IO#timeout= did NOT work on UNIXSocket"
end
begin
file = File.open '/dev/null'
file.timeout = 1
file.read
rescue IO::TimeoutError
puts "IO#timeout= worked on File"
else
puts "IO#timeout= did NOT work on File"
end
Async do
file.read
rescue IO::TimeoutError
puts "IO#timeout= worked on File in Async block"
else
puts "IO#timeout= did NOT work on File in Async block"
endGives me:
IO#timeout= worked on STDIN
IO#timeout= worked on UNIXSocket
IO#timeout= did NOT work on File
IO#timeout= did NOT work on File in Async block
EDIT: It works for IO.fd_for(some_readiness_fd) inside an Async block, but not outside one. For File it doesn't work at all. Is it not supposed to?
There was a problem hiding this comment.
I suppose timeouts should be considered advisory and/or best effort. Like, a safety net.
However, not working for File is probably to be expected, but I wonder if we can improve it. For sure, when running within Async, on the URing backend, it should be possible to make it work.
https://bugs.ruby-lang.org/issues/18630