From: "ioquatix (Samuel Williams)" Date: 2022-03-29T21:58:19+00:00 Subject: [ruby-core:108112] [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). @eregon it makes sense to me to introduce `IO::Timeout` or `IO::TimeoutError` (not sure timeout is strictly an error?). However, how should we handle `Errno::ETIMEDOUT` which can also occur in some system calls. Should we map all `Errno::ETIMEDOUT` -> `IO::Timeout`? The current implementation just uses `Errno::ETIMEDOUT` which is the smallest most compatible change (since technically people should already be expecting IO operations to potentially return `ETIMEDOUT`), e.g. > ETIMEDOUT > The connection timed out during connection establishment, or due to a transmission timeout on active connection. A quick glance at Node.JS seems to be they just use `ETIMEDOUT`. For me, the biggest reason to use a different class would be because we want a more consistent handling of timeouts, across all blocking operations (not just IO ones). It sounds like maybe that ship has sailed because we now have several different exceptions for timeouts, and no common root AFAIK. ---------------------------------------- Feature #18630: Introduce general `IO#timeout` and `IO#timeout=`for all (non-)blocking operations. https://bugs.ruby-lang.org/issues/18630#change-97077 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- I would like us to consider introducing a general IO timeout for all (non-)blocking operations, 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: