]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix race condition inside `git diff-files`
authorepriestley <git@epriestley.com>
Wed, 18 Jun 2014 12:33:05 +0000 (05:33 -0700)
committerepriestley <git@epriestley.com>
Wed, 18 Jun 2014 12:33:05 +0000 (05:33 -0700)
Summary:
There's some sort of race inside `git` here, where the `git diff-files` command exits with different results some of the time when run in parallel with `git ls-files` or `git diff` (running either command was sufficient to trigger the race).

Run it separately to avoid the race.

I poked around the `git` source a little bit but quickly lost interest given that the issue seems fixed and this workaround is essentially reasonable.

Test Plan: Ran test 20x in a row without failures.

Reviewers: hach-que

Reviewed By: hach-que

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D9616

src/repository/api/ArcanistGitAPI.php

index ed8008d83ae87907213d336081b3d8a8977decf5..d637fced45689bee0f4019a11c56fefaaddb03f3 100644 (file)
@@ -600,11 +600,17 @@ final class ArcanistGitAPI extends ArcanistRepositoryAPI {
     $futures = array(
       $uncommitted_future,
       $untracked_future,
-      $unstaged_future,
+      // NOTE: `git diff-files` races with each of these other commands
+      // internally, and resolves with inconsistent results if executed
+      // in parallel. To work around this, DO NOT run it at the same time.
+      // After the other commands exit, we can start the `diff-files` command.
     );
 
     Futures($futures)->resolveAll();
 
+    // We're clear to start the `git diff-files` now.
+    $unstaged_future->start();
+
     $result = new PhutilArrayWithDefaultValue();
 
     list($stdout) = $uncommitted_future->resolvex();