[llvm] r359152 - posix_spawn should retry upon EINTR

JF Bastien via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 16:24:53 PDT 2019


Author: jfb
Date: Wed Apr 24 16:24:53 2019
New Revision: 359152

URL: http://llvm.org/viewvc/llvm-project?rev=359152&view=rev
Log:
posix_spawn should retry upon EINTR

Summary:
We've seen cases of bots failing with:
  clang: error: unable to execute command: posix_spawn failed: Interrupted system call

Add a small retry loop to posix_spawn in case this happens. Don't retry too much in case there's some systemic problem going on, but retry a few times.
<rdar://problem/50181448>

Reviewers: Bigcheese, arphaman

Subscribers: jkorous, dexonsmith, kristina, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D61096

Modified:
    llvm/trunk/lib/Support/Unix/Program.inc

Modified: llvm/trunk/lib/Support/Unix/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Program.inc?rev=359152&r1=359151&r2=359152&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Program.inc (original)
+++ llvm/trunk/lib/Support/Unix/Program.inc Wed Apr 24 16:24:53 2019
@@ -245,12 +245,16 @@ static bool Execute(ProcessInfo &PI, Str
       Envp = const_cast<const char **>(*_NSGetEnviron());
 #endif
 
-    // Explicitly initialized to prevent what appears to be a valgrind false
-    // positive.
-    pid_t PID = 0;
-    int Err = posix_spawn(&PID, Program.str().c_str(), FileActions,
-                          /*attrp*/ nullptr, const_cast<char **>(Argv),
-                          const_cast<char **>(Envp));
+    constexpr int maxRetries = 8;
+    int retries = 0;
+    pid_t PID;
+    int Err;
+    do {
+      PID = 0; // Make Valgrind happy.
+      Err = posix_spawn(&PID, Program.str().c_str(), FileActions,
+                        /*attrp*/ nullptr, const_cast<char **>(Argv),
+                        const_cast<char **>(Envp));
+    } while (Err == EINTR && ++retries < maxRetries);
 
     if (FileActions)
       posix_spawn_file_actions_destroy(FileActions);




More information about the llvm-commits mailing list