From: "ioquatix (Samuel Williams)" Date: 2022-03-17T02:08:45+00:00 Subject: [ruby-core:107935] [Ruby master Feature#18630] Introduce general `IO#timeout` and `IO#timeout=`for all (non-)blocking operations. Issue #18630 has been updated by ioquatix (Samuel Williams). @matz thanks for your comments. > time-out may happen from I/O blocking operations or other CPU bound operation. This proposal only covers I/O blocking. Is it OK? I believe it's acceptable, since it only impacts IO operations. > time-out may not be caused by a single I/O operation, but by multiple operations. This proposal should be updated to address it (maybe specifying time-bound by the specific time point). We still retain `Timeout.timeout` which is sufficient for these cases. > some I/O operation methods takes timeout keyword argument. We need to confirm they are consistent with this proposal. I agree to introduce consistency here where possible. Some method like `gets` and `puts` would be hard to update, but others like `read` and `write` should be possible to add individual timeouts. Later we could consider adding `IO#read_timeout` and `IO#write_timeout` if there is a valid use case. ---------------------------------------- Feature #18630: Introduce general `IO#timeout` and `IO#timeout=`for all (non-)blocking operations. https://bugs.ruby-lang.org/issues/18630#change-96883 * 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: