# Timeout and Exponetial Regexes

**URL:** <https://www.ruby-forum.com/t/timeout-and-exponetial-regexes/70333>\
**Category:** Ruby\
**Created:** [September 28, 2006, 10:17am UTC](https://www.ruby-forum.com/t/timeout-and-exponetial-regexes/70333 "2006-09-28T10:17:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eden\_li](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b19c9b/32.png) [@eden\_li](https://www.ruby-forum.com/u/eden_li)\
**Post date:** [September 28, 2006, 10:17am UTC](https://www.ruby-forum.com/t/timeout-and-exponetial-regexes/70333/1 "2006-09-28T10:17:19Z")

</div>

Side-stepping the debate about running exponential regular expressions  
first place, I’d like to catch a long running regex using  
Timeout.timeout():

$ 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  
1.9?
- 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?
