From: "Eregon (Benoit Daloze)" Date: 2022-10-15T12:04:11+00:00 Subject: [ruby-core:110310] [Ruby master Bug#19055] Regexp.new(regexp, timeout: nil) is intrupted by Regexp.timeout Issue #19055 has been updated by Eregon (Benoit Daloze). I agree timeout=0 should mean immediately. It's already been proposed for `Queue#pop` and `SizedQueue#push`: https://bugs.ruby-lang.org/issues/18982#note-8 / https://github.com/ruby/ruby/pull/6500. I think `timeout: false` for no timeout is the best/clearest. (also Float::INFINITY is quite messy to check for and deal with) > Will it raise an exception before any matching? I think that's implementation details. Because a timeout of 0 has no utility for Regexp I think it doesn't matter much which way it's handled. @mame > It is reasonable to set the global timeout and unset timeout from only limited Regexp instances. Is it though? It's basically breaking the intent of whoever set the global Regexp.timeout. If a Regexp needs a longer time maybe it should just set a higher but not infinite timeout? Although if that's set to a very big number it doesn't help anything in practice. I suppose there might be some legitimate cases though. For example if a gem uses that it could be pretty bad. ---------------------------------------- Bug #19055: Regexp.new(regexp, timeout: nil) is intrupted by Regexp.timeout https://bugs.ruby-lang.org/issues/19055#change-99601 * Author: jaruga (Jun Aruga) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0preview2 (2022-09-09 master 35cfc9a3bb) [x86_64-linux] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- It seems that that a code for `Regexp timeout` written in the release page[1] is actually interrupted by the `Regexp.timeout` (global configuration) in Ruby 3.2.0 preview2 built from the source. Do you know what's wrong? ``` $ cat reg_timeout2.rb Regexp.timeout = 1.0 # This regexp has no timeout long_time_re = Regexp.new("^a*b?a*$", timeout: nil) long_time_re =~ "a" * 50000 + "x" # never interrupted ``` The error `Regexp::TimeoutError` appeared soon after around 1 second after running the script `reg_timeout2.rb`. ``` $ which ruby /usr/local/ruby-3.2.0-preview2/bin/ruby $ ruby -v ruby 3.2.0preview2 (2022-09-09 master 35cfc9a3bb) [x86_64-linux] $ ruby reg_timeout2.rb reg_timeout2.rb:4:in `
': regexp match timeout (Regexp::TimeoutError) $ time ruby reg_timeout2.rb reg_timeout2.rb:4:in `
': regexp match timeout (Regexp::TimeoutError) real 0m1.072s user 0m1.053s sys 0m0.014s $ echo $? 1 ``` ``` $ which irb /usr/local/ruby-3.2.0-preview2/bin/irb $ irb irb(main):001:0> Regexp.timeout = 1.0 => 1.0 irb(main):002:0> long_time_re = Regexp.new("^a*b?a*$", timeout: nil) => /^a*b?a*$/ irb(main):003:0> long_time_re =~ "a" * 50000 + "x" (irb):3:in `
': regexp match timeout (Regexp::TimeoutError) from /usr/local/ruby-3.2.0-preview2/lib/ruby/gems/3.2.0+2/gems/irb-1.4.1/exe/irb:11:in `' from /usr/local/ruby-3.2.0-preview2/bin/irb:25:in `load' from /usr/local/ruby-3.2.0-preview2/bin/irb:25:in `
' irb(main):004:0> ``` [1] https://www.ruby-lang.org/en/news/2022/09/09/ruby-3-2-0-preview2-released/ -- https://bugs.ruby-lang.org/ Unsubscribe: