Project

General

Profile

Actions

Feature #18630

closed

Introduce general `IO#timeout` and `IO#timeout=` for blocking operations.

Added by ioquatix (Samuel Williams) about 2 years ago. Updated over 1 year ago.

Status:
Closed
Target version:
-
[ruby-core:107886]

Description

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:

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0