Timeout and Exponetial Regexes

Side-stepping the debate about running exponential regular expressions
first place, I’d like to catch a long running regex using

$ ruby -v && irb -r timeout
ruby 1.8.4 (2005-12-24) [i486-linux]
irb(main):001:0> Timeout.timeout 5 do ("a"300)+“b” =~ /^(a)*$/ end

Except that it appears the mechanism the Timeout module uses can’t seem
to do this. After looking at the source of Timeout.timeout(), it seems
that the regex is blocking all threads and disallowing the Timeout
mechanism from detecting the runaway block. Indeed, the following
never returns:

irb(main):002:0> t = Thread.new do ("a"300)+“b” =~ /^(a)*$/ end

A few questions:

  • Why do regexes seem to stop up all threads? Is this fixed in ruby
  • Is there a way to offload this processing into another thread
    without resorting to DRb?
  • Is there a better way to detect this sort of thing?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs