bundler/bundler — pull request #2747 by Who828 (2013-12-05 05:40:28+00:00)
Title: Possible fix for gem cache corruption bug because of parallel unix workers

Hey folks,

This might be a possible fix for gem cache corruption bug in Bundler 1.5 rc.1.
We do synchronise using Monitor in case of jruby or if its windows but we don't do it in case of unix workers.

I think we don't need to sync in case of unix workers, if have same number of gems in gemfile as the number of cores in the processor (so each gem will be installed in a new child process, so nothing to worry about), however usually a forked child process installs multiple gems over its lifetime. (e.g. 4 forked process might process 16 gems in the gemfile with 4 each in the ideal situation)

We also make use of threads in forked child process so it doesn't have to get blocked over IO (GIL is released in Ruby when blocked by IO), however because we don't use synchronised pwd and chdir (which internally rubygems uses to install gems) it might be a possible reason for the gem cache corruption.

So in this pull request, I am making sure it uses synchronise chdir and pwd no matter what.