Issue #17849 has been updated by mame (Yusuke Endoh).


Eregon (Benoit Daloze) wrote in #note-22:
> @mame How do you explain the test I linked above fails (still does with latest CRuby) then?

The exception is raised immediately after the block returns, and before `handle_interrupt` returns.

```
$ready = false
thread = Thread.new do
  loop do
    $ready = true
    begin
      Thread.pass
    rescue => e
      p e
    ensure
      Thread.handle_interrupt(Object => :never) do # backtrace reports it happens here
        begin
          Thread.pass
        rescue => e
          abort "ensure saw #{e}"
        end
        $finalized = true
        # the exception is raised immediately after this block returns to handle_interrupt
      end
    end
  end
end

$finalized = false
1000.times {
  Thread.pass until $ready
  thread.raise "timeout"
  Thread.pass
}
p $finalized #=> true
```

----------------------------------------
Feature #17849: Fix Timeout.timeout so that it can be used in threaded Web servers
https://bugs.ruby-lang.org/issues/17849#change-94525

* Author: duerst (Martin Drst)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
Making this a separate issue from #17837

Eregon (Benoit Daloze) wrote in https://bugs.ruby-lang.org/issues/17837#note-10 (which is  about timeouts for regular expressions):

> I think fixing Timeout.timeout might be possible.
> The main/major issue is it can trigger within `ensure`, right? Is there anything else?
> We could automatically mask `Thread#raise` within `ensure` so it only happens after the `ensure` body completes.
> And we could still have a larger "hard timeout" if an `ensure` takes way too long (shouldn't happen, but one cannot be sure).
> I recall discussing this with @schneems some time ago on Twitter.





-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>