Skip to content

Commit

Permalink
Prevent extensions from building in parallel
Browse files Browse the repository at this point in the history
Building an extension requires changing the path so commands executed
via a subprocess will work correctly.  In order to prevent parallel
extension builds from changing each other's directory a mutex is
required.

Fixes #607
  • Loading branch information
drbrain committed Jul 30, 2013
1 parent 39fb5d6 commit 6cbf9b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions History.txt
@@ -1,5 +1,12 @@
# coding: UTF-8

=== 2.0.7

Bug fixes:

* Extensions may now be built in parallel (therefore gems may be installed in
parallel). Bug #606 by Hemant Kumar.

=== 2.0.6 / 2013-07-24

Bug fixes:
Expand Down
19 changes: 15 additions & 4 deletions lib/rubygems/installer.rb
Expand Up @@ -9,6 +9,7 @@
require 'rubygems/ext'
require 'rubygems/user_interaction'
require 'fileutils'
require 'thread'

##
# The installer installs the files contained in the .gem into the Gem.home.
Expand All @@ -31,6 +32,14 @@ class Gem::Installer

ENV_PATHS = %w[/usr/bin/env /bin/env]

##
# The builder shells-out to run various commands after changing the
# directory. This means multiple installations cannot be allowed to build
# extensions in parallel as they may change each other's directories leading
# to broken extensions or failed installations.

CHDIR_MUTEX = Mutex.new # :nodoc:

##
# Raised when there is an error while building extensions.
#
Expand Down Expand Up @@ -675,11 +684,13 @@ def build_extensions
begin
FileUtils.mkdir_p dest_path

Dir.chdir extension_dir do
results = builder.build(extension, gem_dir, dest_path,
results, @build_args)
CHDIR_MUTEX.synchronize do
Dir.chdir extension_dir do
results = builder.build(extension, gem_dir, dest_path,
results, @build_args)

say results.join("\n") if Gem.configuration.really_verbose
say results.join("\n") if Gem.configuration.really_verbose
end
end
rescue
extension_build_error(extension_dir, results.join("\n"), $@)
Expand Down

0 comments on commit 6cbf9b8

Please sign in to comment.