ruby-changes:41119
From: ngoto <ko1@a...>
Date: Fri, 18 Dec 2015 21:33:16 +0900 (JST)
Subject: [ruby-changes:41119] ngoto:r53192 (trunk): * lib/webrick/utils.rb (WEBrick::Utils::TimeoutHandler): To prevent
ngoto 2015-12-18 21:32:53 +0900 (Fri, 18 Dec 2015) New Revision: 53192 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53192 Log: * 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] Modified files: trunk/ChangeLog trunk/lib/webrick/utils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 53191) +++ ChangeLog (revision 53192) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Dec 18 21:26:54 2015 Naohisa Goto <ngotogenome@g...> + + * 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 <ko1@a...> * compile.c (ibf_load_object_string): use fstring if frozen string. Index: lib/webrick/utils.rb =================================================================== --- lib/webrick/utils.rb (revision 53191) +++ lib/webrick/utils.rb (revision 53192) @@ -152,6 +152,7 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L152 TimeoutMutex.synchronize{ @timeout_info = Hash.new } + @queue = Queue.new @watcher = Thread.start{ to_interrupt = [] while true @@ -173,10 +174,14 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L174 } 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 https://github.com/ruby/ruby/blob/trunk/lib/webrick/utils.rb#L205 @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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/