Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Automated g4 rollback of commit 3e5edaf.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Likely cause for b/38172480 ("blaze now waits for all processes spawned by local tests to terminate") and b/38194553 ("Server terminated abruptly (error code: 14, error message: 'Endpoint read failed'").

I have a fix almost ready, but it consists of many lines of new code - we shouldn't rush that into Bazel's 0.5.0 release. Instead, let's roll this back, do a release using the known good older process-wrapper and then go forward in 0.5.1 with a better and well tested new version of this.

*** Original change description ***

process-wrapper: Wait for all (grand)children before exiting.

This uses Linux's PR_SET_CHILD_SUBREAPER and FreeBSD's PROC_REAP_ACQUIRE features to become an init-like process for all (grand)children spawned by process-wrapper, which allows us to a) kill them reliably and then b) wait for them reliably. Before this change, we only killed the main child, waited for it, then fired off a kill -9 on the process group, without waiting for it. This led to a race condition where Bazel would try to use...

***

PiperOrigin-RevId: 156068188
  • Loading branch information
philwo authored and dslomov committed May 15, 2017
1 parent 48034fd commit c4f271d
Show file tree
Hide file tree
Showing 9 changed files with 641 additions and 379 deletions.
31 changes: 6 additions & 25 deletions src/main/tools/BUILD
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
package(default_visibility = ["//src:__subpackages__"])

cc_library(
name = "process-tools",
srcs = [
"process-tools.cc",
"process-tools.h",
],
)

cc_binary(
name = "process-wrapper",
srcs = select({
"//src:windows_msvc": ["process-wrapper-windows.cc"],
"//conditions:default": [
"process-wrapper.cc",
"process-tools.c",
"process-tools.h",
"process-wrapper.c",
],
}),
linkopts = ["-lm"],
deps = select({
copts = select({
"//src:windows_msvc": [],
"//conditions:default": [
":process-tools",
],
"//conditions:default": ["-std=c99"],
}),
linkopts = ["-lm"],
)

cc_binary(
Expand Down Expand Up @@ -53,17 +45,6 @@ cc_binary(
],
}),
linkopts = ["-lm"],
deps = select({
"//src:darwin": [],
"//src:darwin_x86_64": [],
"//src:freebsd": [],
"//src:windows": [],
"//src:windows_msys": [],
"//src:windows_msvc": [],
"//conditions:default": [
":process-tools",
],
}),
)

filegroup(
Expand Down
16 changes: 7 additions & 9 deletions src/main/tools/linux-sandbox-options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "src/main/tools/linux-sandbox-options.h"
#include "linux-sandbox-options.h"
#include "linux-sandbox-utils.h"

#define DIE(args...) \
{ \
fprintf(stderr, __FILE__ ":" S__LINE__ ": \"" args); \
fprintf(stderr, "\": "); \
perror(nullptr); \
perror(NULL); \
exit(EXIT_FAILURE); \
}

Expand All @@ -38,8 +39,6 @@
#include <string>
#include <vector>

#include "src/main/tools/linux-sandbox-utils.h"

using std::ifstream;
using std::unique_ptr;
using std::vector;
Expand Down Expand Up @@ -200,7 +199,6 @@ static void ParseCommandLine(unique_ptr<vector<char *>> args) {
if (optind < static_cast<int>(args->size())) {
if (opt.args.empty()) {
opt.args.assign(args->begin() + optind, args->end());
opt.args.push_back(nullptr);
} else {
Usage(args->front(), "Merging commands not supported.");
}
Expand All @@ -209,8 +207,8 @@ static void ParseCommandLine(unique_ptr<vector<char *>> args) {

// Expands a single argument, expanding options @filename to read in the content
// of the file and add it to the list of processed arguments.
static unique_ptr<vector<char *>> ExpandArgument(
unique_ptr<vector<char *>> expanded, char *arg) {
unique_ptr<vector<char *>> ExpandArgument(unique_ptr<vector<char *>> expanded,
char *arg) {
if (arg[0] == '@') {
const char *filename = arg + 1; // strip off the '@'.
ifstream f(filename);
Expand Down Expand Up @@ -238,7 +236,7 @@ static unique_ptr<vector<char *>> ExpandArgument(
// Pre-processes an argument list, expanding options @filename to read in the
// content of the file and add it to the list of arguments. Stops expanding
// arguments once it encounters "--".
static unique_ptr<vector<char *>> ExpandArguments(const vector<char *> &args) {
unique_ptr<vector<char *>> ExpandArguments(const vector<char *> &args) {
unique_ptr<vector<char *>> expanded(new vector<char *>());
expanded->reserve(args.size());
for (auto arg = args.begin(); arg != args.end(); ++arg) {
Expand All @@ -262,6 +260,6 @@ void ParseOptions(int argc, char *argv[]) {
}

if (opt.working_dir.empty()) {
opt.working_dir = getcwd(nullptr, 0);
opt.working_dir = getcwd(NULL, 0);
}
}
Loading

0 comments on commit c4f271d

Please sign in to comment.