Project

General

Profile

Actions

Bug #21947

closed

`Timeout.timeout` doesn't use `Timeout::ExitException` when Fiber scheduler is in use.

Bug #21947: `Timeout.timeout` doesn't use `Timeout::ExitException` when Fiber scheduler is in use.

Added by ioquatix (Samuel Williams) about 24 hours ago. Updated about 22 hours ago.

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

Description

The following example executes successfully after 7 seconds instead of timing out after 2.

require 'async'
require 'net/http'

start = Time.now

Sync do
  Timeout.timeout 2 do
    Net::HTTP.get(URI 'https://httpbin.org/delay/5')

    puts "...request finished, no timeout though; in #{Time.now - start}s"
  end
end

puts "Duration: #{Time.now - start}s"

# => ...request finished, no timeout though; in 7.7007s
# Duration: 7.700962s

There are two issues:

  • Net::HTTP rescues Timeout::Error and retries. This causes 2s (timeout -> retry) + 5s execution time.
  • Timeout.timeout uses Timeout::ExitException when no exception is specified, but the Fiber scheduler code path was not updated.

See https://github.com/socketry/async/issues/448 for more discussion.

Actions

Also available in: PDF Atom