-
Notifications
You must be signed in to change notification settings - Fork 191
[Compatibility] Adding IO#timeout #3066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
af77b4a
to
f9612a2
Compare
6d60df1
to
e4165b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine. My main concern is we shouldn't make the no-timeout-set case slower, but that seems already fine here.
I wonder if it should only affect read/write though, or other operations as well?
Also could you untag the CRuby tests for this: test/ruby/test_io_timeout.rb
?
490dfbb
to
ab4a579
Compare
759945e
to
cb1fa10
Compare
src/main/ruby/truffleruby/core/io.rb
Outdated
end | ||
|
||
def timeout=(new_timeout) | ||
self.nonblock = !Primitive.nil?(new_timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does io.timeout = nil
sets nonblock to false?
Could you add specs for the interaction of timeout and nonblock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing
cb1fa10
to
92c516a
Compare
92c516a
to
eb27291
Compare
eb27291
to
607745e
Compare
raise(TypeError, 'time interval must not be negative') if seconds < 0 | ||
|
||
seconds | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, it's a proper place for this helper method 👍.
|
||
poll_result = Truffle::IOOperations.poll(io, Truffle::IOOperations::POLLOUT, current_timeout) | ||
raise IO::TimeoutError if poll_result == 0 | ||
Errno.handle_errno(Errno.errno) if poll_result == -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
major: Looks like error handling isn't accurate. Wondering if it's easy to test these cases.
It seems Truffle::IOOperations.poll
:
- returns
false
when it times out - calls
Errno.handle_errno(errno)
and consequently raisesSystemCallError
exception if there is error other thanEINTR
- returns nonnegative
Integer
otherwise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As chatted about this - I'm attempting to update
false # timeout |
false
to 0
. The reason is - Posix's poll does return 0 on timeout (not exactly like this, when timeout happens on an EINTR, but the idea is pretty much equal). As well there is a lot of code doing poll(_) > 0
- which would raise with a boolean result.
And regarding:
calls Errno.handle_errno(errno) and consequently raises SystemCallError exception if there is error other than EINTR
Raising inside poll is fine, as far as I can tell we want that anyways. I would keep the check for -1 in read/write too, just to be safe and pragmatic.
607745e
to
5d9494f
Compare
5d9494f
to
a273dbf
Compare
a273dbf
to
9b3fb03
Compare
af440ac
to
cda497d
Compare
de2a514
to
81dd5c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
Only a few remaining polishing touches needed.
Make timeout to be integer milliseconds in the loop
81dd5c6
to
32f3793
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all the work on this PR, it's a non-trivial piece of functionality to integrate, it looks great.
@itarato FWIW @andrykonchin tried integrating this PR but there have been various issues and corner cases causing issues/hangs/etc in CI, so we eventually moved to some more pressing things. |
Thanks for the ping @eregon, since it was open for a year I figured it's gotta be obsolete. |
Source: #3039
Introduce IO#timeout= and IO#timeout which can cause
IO::TimeoutError to be raised if a blocking operation exceeds the
specified timeout. [Feature #18630]
Caveat
This PR does not contain updating the error type for
TCPSocket
#open
and#new
. It seems we don't have the whole timeout logic implemented for that yet. I rather have them implemented in a separate PR to keep it clean.