Skip to content

Commit 925f4bc

Browse files
committed
Don't join on the stdin pass-through thread.
Since the thread would otherwise block forever waiting for user input, we'll wrap it in a timeout and loop checking the status of the sub-process STDIN pipe. This should prevent runaway thread growth.
1 parent 1568be4 commit 925f4bc

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/svn2git/migration.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'optparse'
22
require 'pp'
33
require 'open4'
4+
require 'timeout'
45

56
module Svn2Git
67
DEFAULT_AUTHORS_FILE = "~/.svn2git/authors"
@@ -376,10 +377,12 @@ def run_command(cmd, exit_on_error=true, printout_output=false)
376377
end
377378
end
378379

379-
threads << Thread.new(stdin) do |stdin|
380-
user_reply = $stdin.gets.chomp
381-
stdin.puts user_reply
382-
stdin.close
380+
Thread.new(stdin) do |stdin|
381+
until $stdin.closed?
382+
user_reply = Timeout.timeout(5) { $stdin.gets.chomp }
383+
stdin.puts user_reply
384+
stdin.close
385+
end
383386
end
384387

385388
threads.each(&:join)

0 commit comments

Comments
 (0)