From: eregontp@... Date: 2021-05-22T19:55:30+00:00 Subject: [ruby-core:103986] [Ruby master Feature#17849] Fix Timeout.timeout so that it can be used in threaded Web servers Issue #17849 has been updated by Eregon (Benoit Daloze). 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. It does not seem to be the case: https://gist.github.com/eregon/9022f5709fa054fc4e488d7de085b254 And I would be surprised if it was on any Ruby, there are two calls there: `handle_interrupt` on `Thread`, and `hash` on `Object`. Actually such a pattern is a typical pitfall of using `handle_interrupt`, and monitor.rb had such a bug. The correct pattern is the first one documented here: https://www.rubydoc.info/stdlib/core/Thread.handle_interrupt Of course that's very verbose and unrealistic to be used for every `ensure`. And additionally it's quite a large overhead when done that way (extra calls, blocks, Hash instances, etc). In other words, we need VM changes to experiment with this. I think masking/disabling interrupts in `ensure` and in `finalizers` (https://bugs.ruby-lang.org/issues/13876#change-91365) would be a good improvement, and definitely worth experimenting with. That won't make `Thread#raise` completely safe indeed, but much more usable, and much safer. Of course, we will need to evaluate the performance and semantics impact of this change. ---------------------------------------- Feature #17849: Fix Timeout.timeout so that it can be used in threaded Web servers https://bugs.ruby-lang.org/issues/17849#change-92119 * Author: duerst (Martin D�rst) * 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: