1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
ngoto 2015-12-15 15:26:47 +00:00
parent cef1f23e89
commit 804720d2eb
2 changed files with 22 additions and 9 deletions

View file

@ -1,3 +1,11 @@
Wed Dec 16 00:25:41 2015 Naohisa Goto <ngotogenome@gmail.com>
* 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]
Tue Dec 15 23:13:10 2015 Naohisa Goto <ngotogenome@gmail.com> Tue Dec 15 23:13:10 2015 Naohisa Goto <ngotogenome@gmail.com>
* gc.c: Delete excess semicolon after RUBY_ALIAS_FUNCTION(). * gc.c: Delete excess semicolon after RUBY_ALIAS_FUNCTION().

View file

@ -154,20 +154,25 @@ module WEBrick
def initialize def initialize
@timeout_info = Hash.new @timeout_info = Hash.new
@watcher = Thread.start{ @watcher = Thread.start{
to_interrupt = []
while true while true
now = Time.now now = Time.now
wakeup = nil wakeup = nil
@timeout_info.each {|thread, ary| to_interrupt.clear
next unless ary TimeoutMutex.synchronize{
ary.dup.each{|info| @timeout_info.each {|thread, ary|
time, exception = *info next unless ary
if time < now ary.each{|info|
interrupt(thread, info.object_id, exception) time, exception = *info
elsif !wakeup || time < wakeup if time < now
wakeup = time to_interrupt.push [thread, info.object_id, exception]
end elsif !wakeup || time < wakeup
wakeup = time
end
}
} }
} }
to_interrupt.each {|arg| interrupt(*arg)}
if !wakeup if !wakeup
sleep sleep
elsif (wakeup -= now) > 0 elsif (wakeup -= now) > 0