Skip to content

Nested timeout supercedes enclosing timeout #312

@roidrage

Description

@roidrage

We ran into an issue recently where, using Timeout.timeout(), we had two nested timeouts set up. The outer one had a smaller timeout than the inner one, which we expected to trigger first, but it didn't. The inner one fired when it's timeout ran out, but the outer one never fired. Here's some code to reproduce the issue:

require 'timeout'

begin
  Timeout.timeout(1) do
    begin
      Timeout.timeout(2) do
        sleep(5)
      end
    rescue Timeout::Error
      puts 'Timeout 2 triggered'
    end
  end
rescue Timeout::Error
  puts 'Timeout 1 triggered'
end

On MRI, the outer timeout triggers after one second, so the inner one never fires. On JRuby (reproduced on 1.6.6 and 1.7.0-preview2), it's the other way around, so the error message will be "Timeout 2 triggered".

I guess given MRI's behaviour it could be assumed to be the expected behaviour in this case?

Let me know if there's any more information I can provide you with!

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions