From: "Eregon (Benoit Daloze)" Date: 2022-03-21T16:59:49+00:00 Subject: [ruby-core:108007] [Ruby master Feature#18630] Introduce general `IO#timeout` and `IO#timeout=`for all (non-)blocking operations. Issue #18630 has been updated by Eregon (Benoit Daloze). I'm still confused, in which cases does this timeout apply? Only non-blocking IO, right? The issue title says: > Introduce general `IO#timeout` and `IO#timeout=`for all (non-)blocking operations. The description says: > I would like us to consider introducing a general timeout for all blocking operations. And the PR says: https://github.com/ruby/ruby/pull/5653/files#diff-92194f057884b3287a3a6bf84e6e3b2bf433a556b68562799252a091744e7854R857 > * Set the internal timeout to the specified duration or nil. The timeout > * applies to all non-blocking operations unless otherwise specified. > * > * This affects the following methods (but is not limited to): #gets, #puts, > * #read, #write, #wait_readable and #wait_writable. This also affects > * non-blocking socket operations like Socket#accept and Socket#connect. But those are not "non-blocking methods" or "non-blocking operations", or at least that's not intuitive. Is the actual condition depending on `IO#nonblock?`, if true possible to timeout all IO operations on it, if false none of them? ---------------------------------------- Feature #18630: Introduce general `IO#timeout` and `IO#timeout=`for all (non-)blocking operations. https://bugs.ruby-lang.org/issues/18630#change-96963 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- I would like us to consider introducing a general timeout for all blocking operations. This timeout can be specified per IO instance. It's useful for ensuring programs don't stop responding or spend an unreasonable amount of time waiting for IO operations. There are effectively two kinds of interfaces that we need to address: - Those that already have a timeout argument (e.g. `wait_readable`) and we follow the existing semantics. - Those that don't have a timeout argument or timeout semantics (e.g. `puts`, `gets`), and thus probably need to raise an exception on timeout. We have three possible kinds of exceptions we could raise: - `Errno::ETIMEDOUT` - `Timeout::Error` (from `timeout.rb`) - Introduce `IO::Timeout` or something similar. Timeout isn't necessarily an error condition. There are different arguments for whether we should define: ```ruby class IO::Timeout < Exception end # or class IO::Timeout < StandardError end ``` I believe the latter (`StandardError`) is more practical but I'm open to either option. I might have more specific arguments later why one is better than the other after testing in a practical system. There is already a PR to try it out: https://github.com/ruby/ruby/pull/5653 -- https://bugs.ruby-lang.org/ Unsubscribe: