From d252c95316ed4c2b7d0ad65efb07468fb26fb589 Mon Sep 17 00:00:00 2001 From: ngoto Date: Tue, 15 Dec 2015 15:26:47 +0000 Subject: * lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler#initialize): TimeoutMutex should be acquired when accessing @timeout_info. To avoid deadlock, interrupt() calls are delayed. Due to the mutex, it is safe to treat ary without ary.dup. [Bug #11742] [ruby-dev:49387] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/webrick/utils.rb | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb index da6386c96c..dc7ce508ea 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -154,20 +154,25 @@ module WEBrick def initialize @timeout_info = Hash.new @watcher = Thread.start{ + to_interrupt = [] while true now = Time.now wakeup = nil - @timeout_info.each {|thread, ary| - next unless ary - ary.dup.each{|info| - time, exception = *info - if time < now - interrupt(thread, info.object_id, exception) - elsif !wakeup || time < wakeup - wakeup = time - end + to_interrupt.clear + TimeoutMutex.synchronize{ + @timeout_info.each {|thread, ary| + next unless ary + ary.each{|info| + time, exception = *info + if time < now + to_interrupt.push [thread, info.object_id, exception] + elsif !wakeup || time < wakeup + wakeup = time + end + } } } + to_interrupt.each {|arg| interrupt(*arg)} if !wakeup sleep elsif (wakeup -= now) > 0 -- cgit v1.2.3