Issue #17849 has been updated by headius (Charles Nutter). mame (Yusuke Endoh) wrote in #note-14: > Just FYI. According to @ko1, masking all exceptions in an ensure clause is possible in pure Ruby, as long as you use MRI. > > ``` > begin > ... > ensure > Thread.handle_interrupt(Object => :never) do > .. > end > end > ``` This is incorrect code. The `handle_interrupt` code must go outside of the entire begin/ensure/end block or you still run the risk of being interrupted before the ensure runs. `handle_interrupt` is a band-aid over the real problem, which is that code can be interrupted at any time. Unfortunately the Ruby Way to fix this is that users have to **opt in** to get safe ensures, and almost nobody gets it right. Every library in existence is broken. And for the record, both JRuby and TruffleRuby fully support `handle_interrupt`, so you don't have to use MRI. ``` Thread.handle_interrupt(Object => :never) do begin Thread.handle_interrupt(Object => :immediate) do ... end ensure ... end end ``` See http://blog.headius.com/2008/02/ruby-threadraise-threadkill-timeoutrb.html `handle_interrupt` makes it possible to avoid some of these problems, but nobody is using it and the ones who are using it are using it wrong. ---------------------------------------- Feature #17849: Fix Timeout.timeout so that it can be used in threaded Web servers https://bugs.ruby-lang.org/issues/17849#change-94056 * 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>