From 0967c1e3ad0fb8d36e0b4fe4117f8e6faca3e9f0 Mon Sep 17 00:00:00 2001 From: ngoto Date: Fri, 18 Dec 2015 12:32:53 +0000 Subject: [PATCH] * lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler): To prevent potential deadlocks, Queue is used to tell update of @timeout_info instead of sleep and wakeup. [Bug #11742] [ruby-dev:49387] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/webrick/utils.rb | 14 ++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index d57dbcc744..5ff41f729b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Dec 18 21:26:54 2015 Naohisa Goto + + * lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler): To prevent + potential deadlocks, Queue is used to tell update of @timeout_info + instead of sleep and wakeup. [Bug #11742] [ruby-dev:49387] + Fri Dec 18 17:24:09 2015 Koichi Sasada * compile.c (ibf_load_object_string): use fstring if frozen string. diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb index f7b4412c19..ed0f3da615 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -152,6 +152,7 @@ module WEBrick TimeoutMutex.synchronize{ @timeout_info = Hash.new } + @queue = Queue.new @watcher = Thread.start{ to_interrupt = [] while true @@ -173,10 +174,14 @@ module WEBrick } to_interrupt.each {|arg| interrupt(*arg)} if !wakeup - sleep + @queue.pop elsif (wakeup -= now) > 0 - sleep(wakeup) + begin + Timeout.timeout(wakeup) { @queue.pop } + rescue Timeout::Error + end end + @queue.clear end } end @@ -200,10 +205,7 @@ module WEBrick @timeout_info[thread] ||= Array.new @timeout_info[thread] << (info = [time, exception]) } - begin - @watcher.wakeup - rescue ThreadError - end + @queue.push nil return info.object_id end