[libc-commits] [PATCH] D76267: [libc] Resolve race condition in sub-process test runner.

Paula Toth via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Mar 16 22:00:35 PDT 2020


PaulkaToast created this revision.
PaulkaToast added reviewers: sivachandra, abrachet.
PaulkaToast added a project: libc-project.
Herald added subscribers: libc-commits, tschuett, jfb, MaskRay.

There seems to be a race condition between the pipe closing and the child process death. Likely these two events are not atomic on some versions of linux.

With the removal of `WNOHANG` we eliminate the race condition, however if the child closes the pipe intentionally then it could result in the test runner hanging. I find this situation less likely, where as I experience failures locally with this race condition rather consistently.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76267

Files:
  libc/utils/testutils/ExecuteFunctionUnix.cpp


Index: libc/utils/testutils/ExecuteFunctionUnix.cpp
===================================================================
--- libc/utils/testutils/ExecuteFunctionUnix.cpp
+++ libc/utils/testutils/ExecuteFunctionUnix.cpp
@@ -67,8 +67,10 @@
   }
 
   int WStatus = 0;
-  int status = ::waitpid(Pid, &WStatus, WNOHANG);
-  assert(status == Pid && "wait call should not block here");
+  pid_t status = ::waitpid(Pid, &WStatus, 0);
+  if (status == -1)
+    return ProcessStatus::Error("waitpid(2) failed");
+  assert(status == Pid);
   (void)status;
   return {WStatus};
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76267.250691.patch
Type: text/x-patch
Size: 568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20200317/05478da9/attachment.bin>


More information about the libc-commits mailing list