Permalink
Browse files

Fix shell bug causing CPU 100%

The SSH sessions loop is trying to IO.select and wait for 0.1 seconds,
but the select is often never reached because it only enters if
readers/writers exist. So the loop executes unchecked at 100% when
waiting for commands. Now we will sleep for 0.1 seconds if we have
no waiting IO.
  • Loading branch information...
1 parent 3100b91 commit f2a787cdc9fbc37567a1798ad94ee22ec442be8c @jpfuentes2 jpfuentes2 committed Dec 18, 2012
Showing with 6 additions and 2 deletions.
  1. +3 −1 lib/capistrano/processable.rb
  2. +3 −1 lib/capistrano/shell.rb
@@ -23,6 +23,8 @@ def process_iteration(wait=nil, &block)
if readers.any? || writers.any?
readers, writers, = IO.select(readers, writers, nil, wait)
+ else
+ return false
end
if readers
@@ -50,4 +52,4 @@ def ensure_each_session
sessions
end
end
-end
+end
@@ -199,11 +199,13 @@ def reader
# thread and generally gets things ready for the REPL.
def setup
configuration.logger.level = Capistrano::Logger::INFO
+ wait_for = 0.1
@mutex = Mutex.new
@bgthread = Thread.new do
loop do
- @mutex.synchronize { process_iteration(0.1) }
+ ret = @mutex.synchronize { process_iteration(wait_for) }
+ sleep wait_for if !ret
end
end
end

0 comments on commit f2a787c

Please sign in to comment.