summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-15 15:26:47 +0000
committerngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-15 15:26:47 +0000
commit804720d2eb2b04ebc9295fc1181185941a889cb5 (patch)
treeb2c04902a634c0c758a9aabc29d2f01fd29d4e40
parentcef1f23e899a9ac36bb5e470b389e5d289f6cb0b (diff)
* 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
-rw-r--r--ChangeLog8
-rw-r--r--lib/webrick/utils.rb23
2 files changed, 22 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 72fc471..884c2bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* gc.c: Delete excess semicolon after RUBY_ALIAS_FUNCTION().
diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb
index da6386c..dc7ce50 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