Skip to content

Commit cac54c4

Browse files
adincebiccopybara-github
authored andcommitted
Print exactly what startup options have changed
Recently I was debugging why my bazel server was getting killed seemingly for no reason and noticed that there is no information in stdout. This would be incredibly helpful to have officially in bazel. Fixes #25364 Closes #26016. PiperOrigin-RevId: 756687906 Change-Id: Id3d6565276a2eb15fbd6f83d0a33fab2e31b3ad8
1 parent b1087dd commit cac54c4

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/main/cpp/blaze.cc

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -984,10 +984,13 @@ static bool IsVolatileArg(const string &arg) {
984984
}
985985

986986
// Returns true if the server needs to be restarted to accommodate changes
987-
// between the two argument lists.
987+
// between the two argument lists. Populates old_server_options and
988+
// new_server_options.
988989
static bool AreStartupOptionsDifferent(
989990
const vector<string> &running_server_args,
990-
const vector<string> &requested_args) {
991+
const vector<string> &requested_args,
992+
vector<string> *old_server_options,
993+
vector<string> *new_server_options) {
991994
// We need not worry about one side missing an argument and the other side
992995
// having the default value, since this command line is the canonical one for
993996
// this version of Bazel: either the default value is listed explicitly or it
@@ -1035,13 +1038,15 @@ static bool AreStartupOptionsDifferent(
10351038
"included in the current request:";
10361039
for (const string &a : old_args) {
10371040
BAZEL_LOG(INFO) << " " << a;
1041+
old_server_options->push_back(a);
10381042
}
10391043
}
10401044
if (!new_args.empty()) {
10411045
BAZEL_LOG(INFO) << "Args from the current request that were not "
10421046
"included when creating the server:";
10431047
for (const string &a : new_args) {
10441048
BAZEL_LOG(INFO) << " " << a;
1049+
new_server_options->push_back(a);
10451050
}
10461051
}
10471052

@@ -1072,11 +1077,31 @@ static bool KillRunningServerIfDifferentStartupOptions(
10721077
// These strings contain null-separated command line arguments. If they are
10731078
// the same, the server can stay alive, otherwise, it needs shuffle off this
10741079
// mortal coil.
1075-
if (AreStartupOptionsDifferent(old_arguments, server_exe_args)) {
1080+
vector<string> old_server_options;
1081+
vector<string> new_server_options;
1082+
if (AreStartupOptionsDifferent(old_arguments, server_exe_args,
1083+
&old_server_options,
1084+
&new_server_options)) {
10761085
logging_info->restart_reason = NEW_OPTIONS;
1077-
BAZEL_LOG(WARNING) << "Running " << startup_options.product_name
1078-
<< " server needs to be killed, because the startup "
1079-
"options are different.";
1086+
1087+
string different_startup_options_message;
1088+
1089+
string old_options_str;
1090+
blaze_util::JoinStrings(old_server_options, ' ', &old_options_str);
1091+
different_startup_options_message +=
1092+
"\n - Only in old server: " + old_options_str;
1093+
1094+
string new_options_str;
1095+
blaze_util::JoinStrings(new_server_options, ' ', &new_options_str);
1096+
different_startup_options_message +=
1097+
"\n - Only in new server: " + new_options_str;
1098+
1099+
BAZEL_LOG(WARNING)
1100+
<< "Running " << startup_options.product_name
1101+
<< " server needs to be killed, because the following startup "
1102+
"options are different:"
1103+
<< different_startup_options_message;
1104+
10801105
server->KillRunningServer();
10811106
return true;
10821107
}

src/test/shell/integration/startup_options_test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ esac
5353
function test_different_startup_options() {
5454
pid=$(bazel --nobatch info server_pid 2> $TEST_log)
5555
[[ -n $pid ]] || fail "Couldn't run ${PRODUCT_NAME}"
56-
newpid=$(bazel --batch info server_pid 2> $TEST_log)
57-
expect_log "WARNING: Running B\\(azel\\|laze\\) server needs to be killed, because the startup options are different."
56+
newpid=$(bazel --batch --host_jvm_args=-Xmx4321m info server_pid 2> $TEST_log)
57+
expect_log "WARNING: Running B\\(azel\\|laze\\) server needs to be killed, because the following startup options are different:
58+
- Only in old server: --noshutdown_on_low_sys_mem
59+
- Only in new server: --batch --host_jvm_args=-Xmx4321m"
5860
[[ "$newpid" != "$pid" ]] || fail "pid $pid was the same!"
5961
if ! "$is_windows"; then
6062
# On Windows: the kill command of MSYS doesn't work for Windows PIDs.

0 commit comments

Comments
 (0)