From: "ioquatix (Samuel Williams)" Date: 2022-03-31T11:46:22+00:00 Subject: [ruby-core:108139] [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). By the way, this still doesn't address that some operations can return `Errno::ETIMEDOUT` and this class of errors is practically speaking the same. I don't have a strong opinion about whether we should force users to write `rescue IO::TimeoutError, Errno::ETIMEDOUT` but it seems more difficult for users. Regarding which operations can give `Errno::ETIMEDOUT` you can check your local man pages: `man -K ETIMEDOUT`. Surprisingly macOS has a ton of hits, even some non-socket cases. I can check Linux too. I guess we need to decide whether we try to incorporate `Errno::ETIMEDOUT` or ignore it. Or maybe another option is to just have a shared module which is included in all of them. ---------------------------------------- Feature #18630: Introduce general `IO#timeout` and `IO#timeout=`for all (non-)blocking operations. https://bugs.ruby-lang.org/issues/18630#change-97115 * 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: